Problem with Setting ForegroundColor and AutoFitColumns


#1

I am currently using 4.0.30 under VB 2005 in a WinApp. Currently using the eval version to test out some features.

The problem I am currently having is with the AutoFitColumns command I have a style that I am setting for a row and that works find, until I call AutoFiltColumns. When I do that the cells loose the forground color.


#2

Could you please post your sample code to show your problem? I will check and fix it ASAP. Thank you very much


#3

Dim xlsWorkbook As New Workbook
Dim strAppPath As String = My.Application.Info.DirectoryPath
Dim dsgTemplate As String = strAppPath & "\Testing.xls"

Dim sqlConn As New SqlConnection("Data Source=SERVER;Initial Catalog=DB;Integrated Security=True")
Dim strSql As String = "Select * From Release"
Dim sqlCmd As New SqlCommand
Dim daTest As New SqlDataAdapter
Dim dtTest As New DataTable

Try
sqlConn.Open()
sqlCmd.CommandText = strSql
sqlCmd.Connection = sqlConn
daTest.SelectCommand = sqlCmd

daTest.Fill(dtTest)

xlsWorkbook.Open(dsgTemplate)

Dim objSheet As Worksheet = xlsWorkbook.Worksheets(0)
objSheet.Cells.ImportDataTable(dtTest, True, 0, 0)
objSheet.Name = "Test"

While xlsWorkbook.Worksheets.Count > 1
xlsWorkbook.Worksheets.RemoveAt(xlsWorkbook.Worksheets.Count - 1)
End While

Dim objCell As Cells = objSheet.Cells
Dim objRow As Rows = objSheet.Cells.Rows
Dim currentRow As Int16 = 1

objSheet.AutoFitColumns()

Dim styles As Styles = xlsWorkbook.Styles
'Set CategoryName style
Dim styleIndex As Integer = styles.Add()
Dim styleCategoryName As Style = styles(styleIndex)
styleCategoryName.HorizontalAlignment = TextAlignmentType.Center
styleCategoryName.ForegroundColor = Color.Blue
styleCategoryName.Pattern = BackgroundType.Solid
styleCategoryName.Font.Size = 10
styleCategoryName.Font.Color = Color.Yellow
styleCategoryName.Font.IsBold = False
styleCategoryName.Font.Name = "Arial"

objRow(0).Style = styleCategoryName
xlsWorkbook.Save("c:\temp.xls")
Process.Start("c:\temp.xls")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try