Spreadsheet ML Text Color (Colour) Rendering - excel
I am writing a tool which generates some Spreadsheet ML (XML) to create an Excel spreadsheet for my users.
I have defined a style as follows:
<Style ss:ID="GreenText">
<Font ss:FontName="Arial" ss:Size="9" ss:Color="#8CBE50" />
</Style>
This works to an extent, but when I open it in Excel the colour rendered for the text isn't the one I specified - it's a brighter version. I can use the same colour reference for a cell border and the colour is rendered correctly.
Can anyone shed any light on why the text colour isn't rendered correctly?
Thanks!
David is correct that Excel 2003 and previous versions of Excel are limited to a 56 color palette.
Excel 2007 added support for 24 bit colors as well as theme colors. Excel 2007 can write xls workbooks which contain this additional color information, and which Excel 2003 can read, but Excel 2003 will still be limited to the 56 color palette. Excel 2007 can load these workbooks and display the exact colors.
SpreadsheetGear for .NET supports the new 24 bit colors and theme colors, as well as the old palette indexed colors, just as Excel 2007 does. You can use SpreadsheetGear to create a workbook with 24 bit colors which will display correctly in Excel 2007, or modify the palette and they will display correctly in Excel 2007 and Excel 2003. Below is an example of both.
You can download a free trial here and try it yourself.
Disclaimer: I own SpreadsheetGear LLC
Here is the sample code:
// 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);
Excel's limited to a palette of 56 colors. It only stores color indexes rather than the actual RGB values. They do permit custom colors in the palette, but I don't know how to change them programmatically.
Edit:
I haven't used office xml documents but this might help (indexedColors tag for defining palette):
http://openxmldeveloper.org/forums/thread/309.aspx
Also there's a Workbook.Colors property for changing the palette from VBA.
Related
WrapText- Auto format cell height
I am using OpenXML to create reports, I am filling data in existing excel template file. In excel template 'Wrap text' for all cells is set to true. When my report is complete I open excel file. In opened file cells are not sized correctly with text wrapping (text wrapping is not applied). Also I observed on machine with office 2007 it works cell are wrapped but on office 2013 cell are not correctly wrapped. If I just double click on any cell then entire row is correctly updated. Can someone please help me in this, is any property \tag I can set in openXML so that on document open cells are correctly shown. Previously we were using OLE office interface there it works always so expectation is it should work with openXML too. Thanks, Dhanaj
Active font color Excel 2010
I am using a worksheet (Excel 2010) on monthly basis and want to use red colour instead of default black. I don't want to change Excel template as I only use red colour for the spreadsheet. At the moment every time I change cell value I need to change font colour again and again as default is black. I read all the tips online and couldn't find any help.
Changing font style in excel from vb6?
i am currently coding a button to transfer all the data from a listview into an excel workbook so it can be printed as barcode labels. the way the barcode works is that it is a true type font. im running into the problem however through vb6 where i dont know how to format a range of cells to have a different font style so i can change certain cells to be able to show barcodes. ive gotten as far as oSheet.range("D2:D10").Font where D2:D10 is not the set range of cells just ones i was playing with. im not sure where to go after the font property here.
Have you tried: oSheet.range("D2:D10").Font.Name = "BarCode Font Name"
Having trouble getting color scale conditional formatting from Excel file to show up in embedded spreadsheet in Windows Form
I have a Windows Form that currently displays a spreadsheet that is editable. I have functionality to allow the user to browse for an Excel file to import to the spreadsheet in the Form view. It is important that an Excel file with a Color Scale Conditional Format be imported with the colors of the cells, as a result of the conditional format, to show up in the embedded spreadsheet. I am currently using SpreadsheetGear's WorkbookView, but I have also discovered that SpreadsheetGear does not handle the conditional formatting with a color scale. Is there a way to either, save the resulting cell colors from my excel object to apply later to the cells in my SpreadsheetGear object? Or, Use a control in the Microsoft.Office.Interop.Excel namespace that DOES handle the color scaling conditional formatting found in existing excel files?
SpreadsheetGear is caught up with Excel's features from Excel 2007 and earlier. It will be a while before SpreadsheetGear implements the Conditional Formatting that includes Color Scaling because that wasn't added to Excel until after the 2007 addition.
Fonts look different when inserting Excel table in a Word document
I am trying to use a VBA macro (for Office 2003) to do the following: In Excel, the user will select a range of cells In Word the user will call the macro (via a button or shortcut) to insert the selected Excel range as an embedded object The code is not the problem so far, my problems are: Given that the user is working in a Word document, most likely will use the same fonts in Excel When Excel range was inserted in Word and they both use the same font names and sizes, they look different inside Word ( fonts look as if they stretched a bit) Styling Cell borders in Excel is not like styling cell borders in Word I do appreciate any advice on this regards
When you paste as an Excel Worksheet Object, what Word is actually displaying is an image created by Excel. Notice that you can't select any text, for example. Word appears to be distorting the image ever so slightly, so that the fonts won't line up. Edit: I can't speak for Office 2003, but Office 2007 defaults to the HTML format using PasteExcelTable. The exact macro statement is Selection.PasteExcelTable False, False, False This will give formatting that is compatible with Word, but unfortunately the data is not live and won't get updated as the spreadsheet is changed. If your requirements don't include live update, try this method.
Is it possible to have the macro creating a table out of the cells (as normally happens when you manually copy them), rather than inserting an Excel Object.
The best visual results results can be achieved by using Selection.CopyPicture(Appearance, Format); however, you will not be able to edit the data inside Word as you will only get a picture.