Excel 电子表格ML文本颜色(颜色)呈现

Excel 电子表格ML文本颜色(颜色)呈现,excel,spreadsheetml,Excel,Spreadsheetml,我正在编写一个工具,生成一些电子表格ML(XML),为我的用户创建一个Excel电子表格 我定义了一种风格,如下所示: <Style ss:ID="GreenText"> <Font ss:FontName="Arial" ss:Size="9" ss:Color="#8CBE50" /> </Style> 这在某种程度上是可行的,但当我在Excel中打开它时,文本呈现的颜色不是我指定的颜色,而是更亮的版本。我可以对单元格边框使用相同的颜色参考,并且颜色渲

我正在编写一个工具,生成一些电子表格ML(XML),为我的用户创建一个Excel电子表格

我定义了一种风格,如下所示:

<Style ss:ID="GreenText"> <Font ss:FontName="Arial" ss:Size="9" ss:Color="#8CBE50" /> </Style> 这在某种程度上是可行的,但当我在Excel中打开它时,文本呈现的颜色不是我指定的颜色,而是更亮的版本。我可以对单元格边框使用相同的颜色参考,并且颜色渲染正确

有人能解释一下为什么文本颜色没有正确呈现吗


谢谢

Excel仅限于56种颜色的调色板。它只存储颜色索引,而不是实际的RGB值。它们允许调色板中的自定义颜色,但我不知道如何通过编程更改它们

编辑:
我没有使用office xml文档,但这可能会有所帮助(用于定义调色板的indexedColors标记):


此外,还有一个工作簿.Colors属性,用于从VBA更改调色板。

Excel仅限于56种颜色的调色板。它只存储颜色索引,而不是实际的RGB值。它们允许调色板中的自定义颜色,但我不知道如何通过编程更改它们

编辑:
我没有使用office xml文档,但这可能会有所帮助(用于定义调色板的indexedColors标记):


另外还有一个工作簿.Colors属性,用于从VBA更改调色板。

David正确地指出,Excel 2003和以前版本的Excel仅限于56个调色板

Excel2007增加了对24位颜色以及主题颜色的支持。Excel 2007可以编写包含此附加颜色信息的xls工作簿,并且Excel 2003可以阅读这些工作簿,但Excel 2003仍将限于56种调色板。Excel 2007可以加载这些工作簿并显示精确的颜色

与Excel 2007一样,支持新的24位颜色和主题颜色,以及旧的调色板索引颜色。您可以使用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);

David是正确的,Excel 2003和以前版本的Excel仅限于56色调色板

Excel2007增加了对24位颜色以及主题颜色的支持。Excel 2007可以编写包含此附加颜色信息的xls工作簿,并且Excel 2003可以阅读这些工作簿,但Excel 2003仍将限于56种调色板。Excel 2007可以加载这些工作簿并显示精确的颜色

与Excel 2007一样,支持新的24位颜色和主题颜色,以及旧的调色板索引颜色。您可以使用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);