Dear Aspose gurus,
I ran into some problems with AutoFitRow after using ImportDataTable to insert a block of rows (representing 1 object).
Problem: I have multiline cells (generated through “\n”) in a column, that do not autofit properly.
First I initiate the workbook with predefined columns:
Workbook outputbook = new Workbook();
outputbook.Worksheets[0].Cells[“A1”].PutValue(“column1”);
outputbook.Worksheets[0].Cells[“B1”].PutValue(“column2”);
outputbook.Worksheets[0].AutoFitColumns();
Next, I build a datatable:
DataTable illustrationTable = new DataTable();
for (int i = 0; i < 2; i++)
illustrationTable.Columns.Add();
DataRow datarow = illustrationTable.NewRow();
datarow.ItemArray = illustrationobject.ToArray();//String[] of length 2.
//Second value is “x” + “\n” + “y” + “\n” etc…
illustrationTable.Rows.Add(datarow);
Then I use the DataTable to fill the worksheet: outputbook.Worksheets[0].Cells.ImportDataTable( illustrationTable, false, 1, 0);
All the data is in the worksheet (so far so good), but now I want to autofit everything:
for (int i = 0; i < outputbook.Worksheets[0].Cells.Rows.Count; i++)
{
outputbook.Worksheets[0].Cells[i, 1].GetStyle().IsTextWrapped = true;
}
outputbook.Worksheets[0].AutoFitRows();
Result:
Column 2 is filled with values displayed in 1 line, on doubleclick on each cell: multiline. The cell has not autofitted to show the vertical list.
I also tried to adjust the style for the entire workbook (no result):
Style style = outputbook.Styles[outputbook.Styles.Add()];
style.IsTextWrapped = true;
Question:
How can I make those cells autofit to show the multiple lines verically?
With kind regards,
Paul
Hi,
Please change the code segment i.e.:
for (int i = 0; i < outputbook.Worksheets[0].Cells.Rows.Count; i++)
{
outputbook.Worksheets[0].Cells[i, 1].GetStyle().IsTextWrapped = true;
}
outputbook.Worksheets[0].AutoFitRows();
{
outputbook.Worksheets[0].Cells[i, 1].GetStyle().IsTextWrapped = true;
}
outputbook.Worksheets[0].AutoFitRows();
to:
for (int i = 0; i < outputbook.Worksheets[0].Cells.Rows.Count; i++)
{
Style style = outputbook.Worksheets[0].Cells[i, 1].GetStyle();
style.IsTextWrapped = true;
outputbook.Worksheets[0].Cells[i, 1].SetStyle(style);
}
outputbook.Worksheets[0].AutoFitRows();
I have tested it works fine.
Thank you.
That did the trick!
thnx!
Hi,
Super!
Good to know that your issue is resolved now.
Have a good day!