/* * Sunil Shenoi, 8-25-2008 * * Assuming cell has a valid string vlaue, find the font record for a given characterIndex * into the stringValue of the cell */ public static FONT getFontForCharacter(Cell cell, UInt16 charIndex) { FONT f = null; int index = cell.Style.RichTextFormat.CharIndexes.BinarySearch(charIndex); List <UInt16> fontIndexList = cell.Style.RichTextFormat.FontIndexes; if (index >= 0) { // found the object, return the font record f = getFontRecord(cell.SharedResource, fontIndexList[index]); //Console.WriteLine("for charIndex={0}, fontIndex={1})", charIndex, fontIndexList[index]); //Console.WriteLine("Object: {0} found at [{1}]", o, index); } else { // would have been inserted before the returned value, so insert just before it if (~index == 0) { //f = getFontRecord(sheet,fontIndexList[0]); //Console.WriteLine("for charIndex={0}, fontIndex=CELL", charIndex); } else { f = getFontRecord(cell.SharedResource, fontIndexList[(~index) - 1]); //Console.WriteLine("for charIndex={0}, fontIndex={1})", charIndex, fontIndexList[(~index) - 1]); } //Console.WriteLine("Object: {0} not found. " // + "Next larger object found at [{1}].", o, ~index); } return(f); }
public SharedResource(bool newbook) { FONT font = new FONT(); font.Height = 200; font.OptionFlags = 0; font.ColorIndex = 32767; font.Weight = 400; font.Escapement = 0; font.Underline = 0; font.CharacterSet = 1; font.Name = "Arial"; //Fonts.Add(font); for (ushort i = 0; i < 21; i++) // required by MS Excel 2003 { XF xf = new XF(); xf.Attributes = 252; xf.CellProtection = 65524; xf.PatternColorIndex = 64; xf.PatternBackgroundColorIndex = 130; xf.FontIndex = 0; xf.FormatIndex = i; ExtendedFormats.Add(xf); } MaxNumberFormatIndex = 163; GetXFIndex(CellFormat.General); SharedStringTable = new SST(); }
private static List <BOUNDSHEET> DecodeRecords(List <Record> records, out SharedResource sharedResource) { sharedResource = new SharedResource(); List <BOUNDSHEET> boundSheets = new List <BOUNDSHEET>(); foreach (Record record in records) { record.Decode(); switch (record.Type) { case RecordType.BOUNDSHEET: boundSheets.Add(record as BOUNDSHEET); break; case RecordType.XF: sharedResource.ExtendedFormats.Add(record as XF); break; case RecordType.FORMAT: sharedResource.CellFormats.Add(record as FORMAT); break; case RecordType.SST: sharedResource.SharedStringTable = record as SST; break; case RecordType.DATEMODE: DATEMODE dateMode = record as DATEMODE; switch (dateMode.Mode) { case 0: sharedResource.BaseDate = DateTime.Parse("1899-12-31"); break; case 1: sharedResource.BaseDate = DateTime.Parse("1904-01-01"); break; } break; case RecordType.PALETTE: PALETTE palette = record as PALETTE; int colorIndex = 8; foreach (int color in palette.Colors) { sharedResource.ColorPalette[colorIndex] = Color.FromArgb(255, 255, 255, 255); colorIndex++; } break; case RecordType.FONT: FONT f = record as FONT; sharedResource.Fonts.Add(f); break; } } return(boundSheets); }