We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Fitting the text into the range

Hello,

I was trying to fit in a long sentence, such as
“AardVaark is the best animal in the world as the foo is the most commonly used function in CS world.” into a range. However, the range that I am working on is only a cell large, that is the range refers to “A1”, and I am doing range.Value = sentence;(this is a super psuedo- code, but you know what I am talking about). Is there any way that I can make the excel show the whole sentence without modifying the range?

Best,
SJ

@SYum

Thanks for your posting and considering Aspose API.

Please use Cell.PutValue() method for your needs instead of using Range. It should fit your needs. See the sample code below.

C#

Workbook wb = new Workbook();

Worksheet ws = wb.Worksheets[0];

Cell a1 = ws.Cells["A1"];
a1.PutValue("Your long sentence.");

Thanks for the reply. However, it seems my code still doesn’t work as desired.
So, I came up with one more question; if I still have a range(I mean the single cell range I mentioned), does the whole text still not show up? Should I delete(or simply not declare) the range and just refer to the single cell by

Worksheet.Cells[]

in order for the whole text to show up?

Best,
SJ

@SYum

Please share your sample code so that I could look into this issue further. Thanks for your cooperation in this regard and have a good day.

@SYum

Thanks for considering Aspose APIs.

You can also wrap the text using the Style.IsTextWrapped property by setting it true.

Please see the following sample code and its comments, its output Excel file as well as screenshot for a reference.

Download Links:
output Excel file.zip (5.6 KB)
sc.png (13.1 KB)

C#

//Create workbook
Workbook wb = new Workbook();

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Put some text in cell C4
Cell cell = ws.Cells["C4"];
cell.PutValue("This is a long text. This is a long text. This is a long text.");

//Wrap the text
Style st = cell.GetStyle();
st.IsTextWrapped = true;
cell.SetStyle(st);

//Save the workbook
wb.Save("output.xlsx");

Screenshot