I'm using Microsoft.Office.Interop.Excel
to create an Excel report from a txt file.
Everything works perfect, but sometimes some columns become extremely large and when we need to print, we need to resize and look horrible.
When I try to break it using Range.Style.WrapText = true
, it looks strange, like this:
I'mthinkingofawaytobreakdownphrasesthathavemorethan20characters.andgetsomethinglikethis:
Theworstthingisthatinexcel,whenIclickonthetext(asIshouldwhenIeditit)itstaysthewayIwantitto.
Here'smycode.
//ignoremoloop,eleéparapegarotextoexatovindodotxtfor(intx=0;x<text.Length-2;x++){if(text[x].Length>20){//fazeraquebra...mascomo?app.Cells[i,j]=text[x+1].Trim();}else{app.Cells[i,j]=text[x+1].Trim();}}//Rangeusadoparaaformatação.RangeformatPaiP1=app.get_Range(letraColunaP1,BuscarAlfabeto(9)+(i).ToString());formatPaiP1.WrapText=true;formatPaiP1.EntireRow.AutoFit();formatPaiP1.VerticalAlignment=Constants.xlCenter;formatPaiP1.EntireColumn.AutoFit();formatPaiP1.Font.Bold=true;formatPaiP1.Font.Name="Arial";
formatPaiP1.Font.Size = 12;