デビッドは、Excel2003および以前のバージョンのExcelが56カラーパレットに制限されていることは正しいです。
Excel 2007では、24ビットカラーとテーマカラーのサポートが追加されました。Excel 2007は、この追加の色情報を含み、Excel 2003が読み取ることができるxlsワークブックを作成できますが、Excel2003は引き続き56カラーパレットに制限されます。Excel 2007は、これらのブックをロードして、正確な色を表示できます。
SpreadsheetGear for .NETは、Excel 2007と同様に、新しい24ビットカラーとテーマカラー、および古いパレットのインデックスカラーをサポートします。SpreadsheetGearを使用して、Excel 2007で正しく表示される24ビットカラーのブックを作成するか、パレットを変更して、Excel2007とExcel2003で正しく表示することができます。以下は両方の例です。
ここから無料トライアルをダウンロードして、自分で試すことができます。
免責事項:私はSpreadsheetGearLLCを所有しています
サンプルコードは次のとおりです。
// 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);