Vb.net 如何在电子表格设备中设置文本和背景色?

Vb.net 如何在电子表格设备中设置文本和背景色?,vb.net,spreadsheetgear,Vb.net,Spreadsheetgear,在SpreadsheetGear 2012中,我要设置: 文本颜色为白色 单元格的背景色为黑色 我试过以下几种: Sheet_Obj.Cells(0,0).Style.NumberFormat = "@" Sheet_Obj.Cells(0,0).Interior.Color = Spreadsheetgear.Color.FromArgb(&H0) Sheet_Obj.Cells(0,0).Style.Font.Color = SpreadsheetGear.Color.FromA

在SpreadsheetGear 2012中,我要设置:

  • 文本颜色为白色
  • 单元格的背景色为黑色
我试过以下几种:

Sheet_Obj.Cells(0,0).Style.NumberFormat = "@"
Sheet_Obj.Cells(0,0).Interior.Color = Spreadsheetgear.Color.FromArgb(&H0)
Sheet_Obj.Cells(0,0).Style.Font.Color = SpreadsheetGear.Color.FromArgb(&HFFFFFF)
Sheet_Obj.Cells(0,0).Value = "Terabytes"
但却无法让任何东西发挥作用

例如:

Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim Sheet_Obj As SpreadsheetGear.IWorksheet = workbook.ActiveWorksheet

' This modifies the format of the cell directly.
Sheet_Obj.Cells(0, 0).Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).NumberFormat = "@"
' This modifies whatever IStyle is currently used by this cell (probably the "Normal" 
' style).  All other cells which also use this still will be affected as well.
Sheet_Obj.Cells(0, 0).Style.Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Style.Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).Style.NumberFormat = "@"

' Assuming you are modifying the "Normal" style, this code is equivalent to the above code.
Dim style As SpreadsheetGear.IStyle = workbook.Styles("Normal")
style.Interior.Color = SpreadsheetGear.Colors.Black
style.Font.Color = SpreadsheetGear.Colors.White
style.NumberFormat = "@"

您的代码将格式直接应用于单元格本身,而不是单元格使用的单元格样式。请参阅我的答案,了解更多详细信息

如果只想使用特定格式影响特定单元格,则需要使用IRangeIRange..颜色/等示例:

Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim Sheet_Obj As SpreadsheetGear.IWorksheet = workbook.ActiveWorksheet

' This modifies the format of the cell directly.
Sheet_Obj.Cells(0, 0).Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).NumberFormat = "@"
' This modifies whatever IStyle is currently used by this cell (probably the "Normal" 
' style).  All other cells which also use this still will be affected as well.
Sheet_Obj.Cells(0, 0).Style.Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Style.Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).Style.NumberFormat = "@"

' Assuming you are modifying the "Normal" style, this code is equivalent to the above code.
Dim style As SpreadsheetGear.IStyle = workbook.Styles("Normal")
style.Interior.Color = SpreadsheetGear.Colors.Black
style.Font.Color = SpreadsheetGear.Colors.White
style.NumberFormat = "@"
如果希望工作簿中的所有单元格都具有特定格式,那么修改这些单元格使用的样式(默认情况下为“正常”样式)将是一个很好的方法。您可以通过IRange访问特定单元格使用的电流。。您可以通过IWorkbook访问整个系统。收集例如:

Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim Sheet_Obj As SpreadsheetGear.IWorksheet = workbook.ActiveWorksheet

' This modifies the format of the cell directly.
Sheet_Obj.Cells(0, 0).Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).NumberFormat = "@"
' This modifies whatever IStyle is currently used by this cell (probably the "Normal" 
' style).  All other cells which also use this still will be affected as well.
Sheet_Obj.Cells(0, 0).Style.Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Style.Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).Style.NumberFormat = "@"

' Assuming you are modifying the "Normal" style, this code is equivalent to the above code.
Dim style As SpreadsheetGear.IStyle = workbook.Styles("Normal")
style.Interior.Color = SpreadsheetGear.Colors.Black
style.Font.Color = SpreadsheetGear.Colors.White
style.NumberFormat = "@"

您的代码将格式直接应用于单元格本身,而不是单元格使用的单元格样式。请参阅我的答案,了解更多详细信息

如果只想使用特定格式影响特定单元格,则需要使用IRangeIRange..颜色/等示例:

Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim Sheet_Obj As SpreadsheetGear.IWorksheet = workbook.ActiveWorksheet

' This modifies the format of the cell directly.
Sheet_Obj.Cells(0, 0).Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).NumberFormat = "@"
' This modifies whatever IStyle is currently used by this cell (probably the "Normal" 
' style).  All other cells which also use this still will be affected as well.
Sheet_Obj.Cells(0, 0).Style.Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Style.Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).Style.NumberFormat = "@"

' Assuming you are modifying the "Normal" style, this code is equivalent to the above code.
Dim style As SpreadsheetGear.IStyle = workbook.Styles("Normal")
style.Interior.Color = SpreadsheetGear.Colors.Black
style.Font.Color = SpreadsheetGear.Colors.White
style.NumberFormat = "@"
如果希望工作簿中的所有单元格都具有特定格式,那么修改这些单元格使用的样式(默认情况下为“正常”样式)将是一个很好的方法。您可以通过IRange访问特定单元格使用的电流。。您可以通过IWorkbook访问整个系统。收集例如:

Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim Sheet_Obj As SpreadsheetGear.IWorksheet = workbook.ActiveWorksheet

' This modifies the format of the cell directly.
Sheet_Obj.Cells(0, 0).Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).NumberFormat = "@"
' This modifies whatever IStyle is currently used by this cell (probably the "Normal" 
' style).  All other cells which also use this still will be affected as well.
Sheet_Obj.Cells(0, 0).Style.Interior.Color = SpreadsheetGear.Colors.Black
Sheet_Obj.Cells(0, 0).Style.Font.Color = SpreadsheetGear.Colors.White
Sheet_Obj.Cells(0, 0).Style.NumberFormat = "@"

' Assuming you are modifying the "Normal" style, this code is equivalent to the above code.
Dim style As SpreadsheetGear.IStyle = workbook.Styles("Normal")
style.Interior.Color = SpreadsheetGear.Colors.Black
style.Font.Color = SpreadsheetGear.Colors.White
style.NumberFormat = "@"