Reputation: 4789
when i convert datatable to .csv my excel sheets are generated as below:
and tried like below:
sw.Write(string.Format("=\"{0}\"", drow[i].ToString()));
then my excel sheets were like:
note that cells have =" " characters;
i'm trying to do like auto fit width & height of each cells programmatically. How?
Upvotes: 12
Views: 59280
Reputation: 51
This questions just helped me to solve part of a problem.
I had to copy the data to a secondary, auxiliary sheet, then send it to the datagrid, but when I did, it would display in the datagrid the sequence of ######### for some of my data that was larger than the field itself.
So I used
**sheets.UsedRange.Columns.AutoFit();**
to solve the problem every time a new column is created.
Where sheets is my variable who received the **Microsoft.Office.Interop.Excel.Worksheet**
.
Thank you guys very much.
Upvotes: 2
Reputation: 1825
Try getting the range and then do Autofit
Range.Rows.AutoFit();
Range.Columns.AutoFit();
Upvotes: 19
Reputation: 67
I found this on another page:
C#
// Automatically set the width on columns B and C. worksheet.Cells["B:C"].Columns.AutoFit();
// Set the row height to automatic on rows 7 through 9. worksheet.Cells["7:9"].Rows.AutoFit();
Upvotes: 1