David 是正确的,Excel 2003 和早期版本的 Excel 仅限于 56 个调色板。
Excel 2007 添加了对 24 位颜色和主题颜色的支持。Excel 2007 可以编写包含此附加颜色信息的 xls 工作簿,并且 Excel 2003 可以读取这些工作簿,但 Excel 2003 仍将仅限于 56 种调色板。Excel 2007 可以加载这些工作簿并显示准确的颜色。
SpreadsheetGear for .NET支持新的 24 位颜色和主题颜色,以及旧的调色板索引颜色,就像 Excel 2007 一样。您可以使用 SpreadsheetGear 创建一个 24 位颜色的工作簿,该工作簿将在 Excel 2007 中正确显示,或者修改调色板,它们将在 Excel 2007 和 Excel 2003 中正确显示。下面是两者的示例。
您可以在此处下载免费试用版并亲自试用。
免责声明:我拥有 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);