David是正确的,Excel 2003和以前版本的Excel仅限于56色调色板。
Excel 2007增加了对24位色以及主题颜色的支持。 Excel 2007可以编写包含此附加颜色信息和Excel 2003可以读取的xls工作簿,但Excel 2003仍将限制为56色调色板。 Excel 2007可以加载这些工作簿并显示确切的颜色。
支持新的24位颜色和主题颜色,以及旧的调色板索引颜色,就像Excel 2007一样。您可以使用SpreadsheetGear创建一个24位颜色的工作簿,该工作簿将在Excel 2007中正确显示,或者修改调色板,并且它们将在Excel 2007和Excel 2003中正确显示。下面是两个示例。
您可以下载免费试用here并自己尝试。
声明:我自己的SpreadsheetGear LLC
下面是示例代码:
// Create a new empty workbook with one worksheet.
IWorkbook workbook = Factory.GetWorkbook();
// Get the worksheet and change it's name to "Person".
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Name = "Colors";
// Put "Hello World!" into A1.
IRange a1 = worksheet.Cells["A1"];
a1.Value = "Hello World!";
a1.Font.Color = System.Drawing.Color.FromArgb(0x8C, 0xBE, 0x50);
// Save the workbook as xls (Excel 97-2003/Biff8) with default palette.
//
// This workbook will display the exact color in Excel 2007 and
// SpreadsheetGear 2009, but will only display the closest available
// palette indexed color in Excel 2003.
workbook.SaveAs(@"C:\tmp\GreenDefaultPalette.xls", FileFormat.Excel8);
// Save as xlsx/Open XML which will also display the exact color.
workbook.SaveAs(@"C:\tmp\GreenDefaultPalette.xlsx", FileFormat.OpenXMLWorkbook);
// Now, modify the palette and save. This workbook will display the exact
// color in Excel 2003 as well as in SpreadsheetGear 2009 and Excel 2007.
//
// Note that modifying the palette will change the color of any cells which
// already reference this palette indexed color - so be careful if you are
// modifying pre-existing workbooks.
workbook.Colors[0] = a1.Font.Color;
workbook.SaveAs(@"C:\tmp\GreenModifiedPalette.xls", FileFormat.Excel8);