Free Support Forum - aspose.com

How to set a column to wrap text?


#1

Hi there,

I have seen many posts about how to set individual cells to wrap text, but none to set the text wrap for a whole column. To clarify, I’d like to programmatically do what the button that is highlighted in the attached image does.

Many thanks and kind regards,
Sheridan

Capture.PNG (5.4 KB)


#2

@workshare,

You may please try following sample code which set a column to wrap text and provide your feedback.

Workbook wb = new Workbook(path + "Book1.xlsx");
Worksheet _worksheet = wb.Worksheets[0];

// Create a Style object using CellsFactory class
CellsFactory cf = new CellsFactory();
Aspose.Cells.Style st = cf.CreateStyle();
st.IsTextWrapped = true;
_worksheet.Cells.Columns[0].ApplyStyle(st, new StyleFlag() { WrapText = true });
_worksheet.Cells.Columns[0].Width = 10;
wb.Save(path + "output.xlsx");

#3

Wow, I would not have guessed that. No wonder I couldn’t work it out.

Thank you very much.
Kind regards,
Sheridan


#4

@workshare,

Good to know that the suggested code segment figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.