AutoSizeColumn Does Not Work as Advertised in Release 1.2.2 for Net 2.0

Apr 1, 2010 at 12:52 AM

I downloaded the 1.2.2 bins and tried the autosizecolumn as:

            'Format the columns
            For I = 0 To NCol - 1
                'xlWorkSheet.SetColumnWidth(I, 15 * 256)
                xlWorkSheet.AutoSizeColumn(I)
            Next
The columns still appear as they would if I did no autosizecolumn.  Any suggestions?
Apr 4, 2010 at 7:14 PM

Are these discussions monitored and answered?

Apr 6, 2010 at 5:15 AM

How did you create your rows and columns?

I've seen this problem if you do not check whether a row or column exists before adding it.

This is what I do, and it works correctly in 1.2.2 alpha:

 

            var row = Sheet.GetRow(rowNumber) ?? Sheet.CreateRow(rowNumber);
            var cell = row.GetCell(columnNumber) ?? row.CreateCell(columnNumber);

 

var row = sheet.GetRow(rowNumber) ?? sheet.CreateRow(rowNumber);
var cell = row.GetCell(columnNumber) ?? row.CreateCell(columnNumber);

 

Apr 6, 2010 at 8:08 AM

Indeed the autosize worked when I used (in my workbook creation loop):

Dim Row As HSSFRow = xlWorkSheet.CreateRow(NLines)
Row.CreateCell(0).SetCellValue(AddressBlock)
Row.CreateCell(1).SetCellValue(Salutation)
Row.CreateCell(2).SetCellValue(First)
Row.CreateCell(3).SetCellValue(Last)
Row.CreateCell(4).SetCellValue(HomePhone)
Row.CreateCell(5).SetCellValue(MobilePhone)
Row.CreateCell(6).SetCellValue(BusinessPhone)
Instead of 

<font size="2">

 

</font>

xlWorkSheet.CreateRow(NLines).CreateCell(0).SetCellValue(AddressBlock)
xlWorkSheet.CreateRow(NLines).CreateCell(1).SetCellValue(Salutation)
xlWorkSheet.CreateRow(NLines).CreateCell(2).SetCellValue(First)
xlWorkSheet.CreateRow(NLines).CreateCell(3).SetCellValue(Last)
xlWorkSheet.CreateRow(NLines).CreateCell(4).SetCellValue(HomePhone)
xlWorkSheet.CreateRow(NLines).CreateCell(5).SetCellValue(MobilePhone)
xlWorkSheet.CreateRow(NLines).CreateCell(6).SetCellValue(BusinessPhone)

Do you know how I can set a column to "wrap"?

 

Apr 6, 2010 at 9:17 AM

The following worked to set the column to wrap.  I found that it must be done just after the first row is created, else it had no effect.

            'wrap the address block
            Dim WT As HSSFCellStyle = xlWorkBook.CreateCellStyle
            WT.WrapText = True
            xlWorkSheet.SetDefaultColumnStyle(1, WT)