public void SetUp() { stylesTable = new StylesTable(); ctStylesheet = stylesTable.GetCTStylesheet(); ctBorderA = new CT_Border(); XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA); long borderId = stylesTable.PutBorder(borderA); Assert.AreEqual(1, borderId); XSSFCellBorder borderB = new XSSFCellBorder(); Assert.AreEqual(1, stylesTable.PutBorder(borderB)); ctFill = new CT_Fill(); XSSFCellFill fill = new XSSFCellFill(ctFill); long fillId = stylesTable.PutFill(fill); Assert.AreEqual(2, fillId); ctFont = new CT_Font(); XSSFFont font = new XSSFFont(ctFont); long fontId = stylesTable.PutFont(font); Assert.AreEqual(1, fontId); cellStyleXf = ctStylesheet.AddNewCellStyleXfs().AddNewXf(); cellStyleXf.borderId = 1; cellStyleXf.fillId = 1; cellStyleXf.fontId = 1; cellXfs = ctStylesheet.AddNewCellXfs(); cellXf = cellXfs.AddNewXf(); cellXf.xfId = (1); cellXf.borderId = (1); cellXf.fillId = (1); cellXf.fontId = (1); stylesTable.PutCellStyleXf(cellStyleXf); stylesTable.PutCellXf(cellXf); cellStyle = new XSSFCellStyle(1, 1, stylesTable, null); }
public void SetUp() { stylesTable = new StylesTable(); ctStylesheet = stylesTable.GetCTStylesheet(); ctBorderA = new CT_Border(); XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA); long borderId = stylesTable.PutBorder(borderA); Assert.AreEqual(1, borderId); XSSFCellBorder borderB = new XSSFCellBorder(); Assert.AreEqual(1, stylesTable.PutBorder(borderB)); ctFill = new CT_Fill(); XSSFCellFill fill = new XSSFCellFill(ctFill); long fillId = stylesTable.PutFill(fill); Assert.AreEqual(2, fillId); ctFont = new CT_Font(); XSSFFont font = new XSSFFont(ctFont); long fontId = stylesTable.PutFont(font); Assert.AreEqual(1, fontId); cellStyleXf = ctStylesheet.AddNewCellStyleXfs().AddNewXf(); cellStyleXf.borderId = 1; cellStyleXf.fillId = 1; cellStyleXf.fontId = 1; cellXfs = ctStylesheet.AddNewCellXfs(); cellXf = cellXfs.AddNewXf(); cellXf.xfId = (1); cellXf.borderId = (1); cellXf.fillId = (1); cellXf.fontId = (1); stylesTable.PutCellStyleXf(cellStyleXf); stylesTable.PutCellXf(cellXf); cellStyle = new XSSFCellStyle(1, 1, stylesTable, null); Assert.IsNotNull(stylesTable.GetFillAt(1).GetCTFill().patternFill); Assert.AreEqual(ST_PatternType.darkGray, stylesTable.GetFillAt(1).GetCTFill().patternFill.patternType); }
public void Bug58996_UsedToWorkIn3_11_ButNotIn3_13() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFCellStyle cellStyle = workbook.CreateCellStyle() as XSSFCellStyle; cellStyle.FillForegroundColorColor = (null); Assert.IsNull(cellStyle.FillForegroundColorColor); cellStyle.FillBackgroundColorColor = (null); Assert.IsNull(cellStyle.FillBackgroundColorColor); cellStyle.FillPattern = FillPatternType.NoFill;; Assert.AreEqual(FillPatternType.NoFill, cellStyle.FillPattern); cellStyle.SetBottomBorderColor(null); Assert.IsNull(cellStyle.BottomBorderXSSFColor); cellStyle.SetTopBorderColor(null); Assert.IsNull(cellStyle.TopBorderXSSFColor); cellStyle.SetLeftBorderColor(null); Assert.IsNull(cellStyle.LeftBorderXSSFColor); cellStyle.SetRightBorderColor(null); Assert.IsNull(cellStyle.RightBorderXSSFColor); }
public void TestGetCellStyleAt() { XSSFWorkbook workbook = new XSSFWorkbook(); short i = 0; //get default style ICellStyle cellStyleAt = workbook.GetCellStyleAt(i); Assert.IsNotNull(cellStyleAt); //get custom style StylesTable styleSource = workbook.GetStylesSource(); XSSFCellStyle customStyle = new XSSFCellStyle(styleSource); XSSFFont font = new XSSFFont(); font.FontName = ("Verdana"); customStyle.SetFont(font); int x = styleSource.PutStyle(customStyle); cellStyleAt = workbook.GetCellStyleAt((short)x); Assert.IsNotNull(cellStyleAt); }
public void TestCloneStyleSameWB() { XSSFWorkbook wb = new XSSFWorkbook(); Assert.AreEqual(1, wb.NumberOfFonts); XSSFFont fnt = (XSSFFont)wb.CreateFont(); fnt.FontName = ("TestingFont"); Assert.AreEqual(2, wb.NumberOfFonts); XSSFCellStyle orig = (XSSFCellStyle)wb.CreateCellStyle(); orig.Alignment = (HorizontalAlignment.Right); orig.SetFont(fnt); orig.DataFormat = (short)18; Assert.AreEqual(HorizontalAlignment.Right, orig.Alignment); Assert.AreEqual(fnt, orig.GetFont()); Assert.AreEqual(18, orig.DataFormat); XSSFCellStyle clone = (XSSFCellStyle)wb.CreateCellStyle(); Assert.AreNotEqual(HorizontalAlignment.Right, clone.Alignment); Assert.AreNotEqual(fnt, clone.GetFont()); Assert.AreNotEqual(18, clone.DataFormat); clone.CloneStyleFrom(orig); Assert.AreEqual(HorizontalAlignment.Right, clone.Alignment); Assert.AreEqual(fnt, clone.GetFont()); Assert.AreEqual(18, clone.DataFormat); Assert.AreEqual(2, wb.NumberOfFonts); clone.Alignment = HorizontalAlignment.Left; clone.DataFormat = 17; Assert.AreEqual(HorizontalAlignment.Right, orig.Alignment); Assert.AreEqual(18, orig.DataFormat); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
public void TestGetFillForegroundColor() { XSSFWorkbook wb = new XSSFWorkbook(); StylesTable styles = wb.GetStylesSource(); Assert.AreEqual(1, wb.NumCellStyles); Assert.AreEqual(2, styles.GetFills().Count); XSSFCellStyle defaultStyle = (XSSFCellStyle)wb.GetCellStyleAt((short)0); Assert.AreEqual(IndexedColors.Automatic.Index, defaultStyle.FillForegroundColor); Assert.AreEqual(null, defaultStyle.FillForegroundColorColor); Assert.AreEqual(FillPatternType.NoFill, defaultStyle.FillPattern); XSSFCellStyle customStyle = (XSSFCellStyle)wb.CreateCellStyle(); customStyle.FillPattern = (FillPatternType.SolidForeground); Assert.AreEqual(FillPatternType.SolidForeground, customStyle.FillPattern); Assert.AreEqual(3, styles.GetFills().Count); customStyle.FillForegroundColor = (IndexedColors.BrightGreen.Index); Assert.AreEqual(IndexedColors.BrightGreen.Index, customStyle.FillForegroundColor); Assert.AreEqual(4, styles.GetFills().Count); for (int i = 0; i < 3; i++) { XSSFCellStyle style = (XSSFCellStyle)wb.CreateCellStyle(); style.FillPattern = (FillPatternType.SolidForeground); Assert.AreEqual(FillPatternType.SolidForeground, style.FillPattern); Assert.AreEqual(4, styles.GetFills().Count); style.FillForegroundColor = (IndexedColors.BrightGreen.Index); Assert.AreEqual(IndexedColors.BrightGreen.Index, style.FillForegroundColor); Assert.AreEqual(4, styles.GetFills().Count); } Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb)); }
public void TestGetFillForegroundColor() { XSSFWorkbook wb = new XSSFWorkbook(); StylesTable styles = wb.GetStylesSource(); Assert.AreEqual(1, wb.NumCellStyles); Assert.AreEqual(2, styles.GetFills().Count); XSSFCellStyle defaultStyle = (XSSFCellStyle)wb.GetCellStyleAt((short)0); Assert.AreEqual(IndexedColors.AUTOMATIC.Index, defaultStyle.FillForegroundColor); Assert.AreEqual(null, defaultStyle.FillForegroundColorColor); Assert.AreEqual(FillPatternType.NO_FILL, defaultStyle.FillPattern); XSSFCellStyle customStyle = (XSSFCellStyle)wb.CreateCellStyle(); customStyle.FillPattern = (FillPatternType.SOLID_FOREGROUND); Assert.AreEqual(FillPatternType.SOLID_FOREGROUND, customStyle.FillPattern); Assert.AreEqual(3, styles.GetFills().Count); customStyle.FillForegroundColor = (IndexedColors.BRIGHT_GREEN.Index); Assert.AreEqual(IndexedColors.BRIGHT_GREEN.Index, customStyle.FillForegroundColor); Assert.AreEqual(4, styles.GetFills().Count); for (int i = 0; i < 3; i++) { XSSFCellStyle style = (XSSFCellStyle)wb.CreateCellStyle(); style.FillPattern = (FillPatternType.SOLID_FOREGROUND); Assert.AreEqual(FillPatternType.SOLID_FOREGROUND, style.FillPattern); Assert.AreEqual(4, styles.GetFills().Count); style.FillForegroundColor = (IndexedColors.BRIGHT_GREEN.Index); Assert.AreEqual(IndexedColors.BRIGHT_GREEN.Index, style.FillForegroundColor); Assert.AreEqual(4, styles.GetFills().Count); } }
public int PutStyle(XSSFCellStyle style) { CT_Xf mainXF = style.GetCoreXf(); if (!xfs.Contains(mainXF)) { xfs.Add(mainXF); } return xfs.IndexOf(mainXF); }
public void TestCloneStyleDiffWB() { XSSFWorkbook wbOrig = new XSSFWorkbook(); Assert.AreEqual(1, wbOrig.NumberOfFonts); Assert.AreEqual(0, wbOrig.GetStylesSource().GetNumberFormats().Count); XSSFFont fnt = (XSSFFont)wbOrig.CreateFont(); fnt.FontName = ("TestingFont"); Assert.AreEqual(2, wbOrig.NumberOfFonts); Assert.AreEqual(0, wbOrig.GetStylesSource().GetNumberFormats().Count); XSSFDataFormat fmt = (XSSFDataFormat)wbOrig.CreateDataFormat(); fmt.GetFormat("MadeUpOne"); fmt.GetFormat("MadeUpTwo"); XSSFCellStyle orig = (XSSFCellStyle)wbOrig.CreateCellStyle(); orig.Alignment = (HorizontalAlignment.Right); orig.SetFont(fnt); orig.DataFormat = (fmt.GetFormat("Test##")); Assert.IsTrue(HorizontalAlignment.Right == orig.Alignment); Assert.IsTrue(fnt == orig.GetFont()); Assert.IsTrue(fmt.GetFormat("Test##") == orig.DataFormat); Assert.AreEqual(2, wbOrig.NumberOfFonts); Assert.AreEqual(3, wbOrig.GetStylesSource().GetNumberFormats().Count); // Now a style on another workbook XSSFWorkbook wbClone = new XSSFWorkbook(); Assert.AreEqual(1, wbClone.NumberOfFonts); Assert.AreEqual(0, wbClone.GetStylesSource().GetNumberFormats().Count); Assert.AreEqual(1, wbClone.NumCellStyles); XSSFDataFormat fmtClone = (XSSFDataFormat)wbClone.CreateDataFormat(); XSSFCellStyle clone = (XSSFCellStyle)wbClone.CreateCellStyle(); Assert.AreEqual(1, wbClone.NumberOfFonts); Assert.AreEqual(0, wbClone.GetStylesSource().GetNumberFormats().Count); Assert.IsFalse(HorizontalAlignment.Right == clone.Alignment); Assert.IsFalse("TestingFont" == clone.GetFont().FontName); clone.CloneStyleFrom(orig); Assert.AreEqual(2, wbClone.NumberOfFonts); Assert.AreEqual(2, wbClone.NumCellStyles); Assert.AreEqual(1, wbClone.GetStylesSource().GetNumberFormats().Count); Assert.AreEqual(HorizontalAlignment.Right, clone.Alignment); Assert.AreEqual("TestingFont", clone.GetFont().FontName); Assert.AreEqual(fmtClone.GetFormat("Test##"), clone.DataFormat); Assert.IsFalse(fmtClone.GetFormat("Test##") == fmt.GetFormat("Test##")); // Save it and re-check XSSFWorkbook wbReload = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(wbClone); Assert.AreEqual(2, wbReload.NumberOfFonts); Assert.AreEqual(2, wbReload.NumCellStyles); Assert.AreEqual(1, wbReload.GetStylesSource().GetNumberFormats().Count); XSSFCellStyle reload = (XSSFCellStyle)wbReload.GetCellStyleAt((short)1); Assert.AreEqual(HorizontalAlignment.Right, reload.Alignment); Assert.AreEqual("TestingFont", reload.GetFont().FontName); Assert.AreEqual(fmtClone.GetFormat("Test##"), reload.DataFormat); Assert.IsFalse(fmtClone.GetFormat("Test##") == fmt.GetFormat("Test##")); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wbOrig)); Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wbClone)); }
public void TestGetCellStyleAt() { XSSFWorkbook workbook = new XSSFWorkbook(); short i = 0; //get default style ICellStyle cellStyleAt = workbook.GetCellStyleAt(i); Assert.IsNotNull(cellStyleAt); //get custom style StylesTable styleSource = workbook.GetStylesSource(); XSSFCellStyle customStyle = new XSSFCellStyle(styleSource); XSSFFont font = new XSSFFont(); font.FontName = ("Verdana"); customStyle.SetFont(font); int x = styleSource.PutStyle(customStyle); cellStyleAt = workbook.GetCellStyleAt((short)x); Assert.IsNotNull(cellStyleAt); }
public void TestSetDefaultColumnStyle() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet(); CT_Worksheet ctWorksheet = sheet.GetCTWorksheet(); StylesTable stylesTable = workbook.GetStylesSource(); XSSFFont font = new XSSFFont(); font.FontName = ("Cambria"); stylesTable.PutFont(font); CT_Xf cellStyleXf = new CT_Xf(); cellStyleXf.fontId = (1); cellStyleXf.fillId= 0; cellStyleXf.borderId= 0; cellStyleXf.numFmtId= 0; stylesTable.PutCellStyleXf(cellStyleXf); CT_Xf cellXf = new CT_Xf(); cellXf.xfId = (1); stylesTable.PutCellXf(cellXf); XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable, null); Assert.AreEqual(1, cellStyle.FontIndex); sheet.SetDefaultColumnStyle(3, cellStyle); Assert.AreEqual(1u, ctWorksheet.GetColsArray(0).GetColArray(0).style); }
/** * Clones all the style information from another * XSSFCellStyle, onto this one. This * XSSFCellStyle will then have all the same * properties as the source, but the two may * be edited independently. * Any stylings on this XSSFCellStyle will be lost! * * The source XSSFCellStyle could be from another * XSSFWorkbook if you like. This allows you to * copy styles from one XSSFWorkbook to another. */ public void CloneStyleFrom(ICellStyle source) { if (source is XSSFCellStyle) { XSSFCellStyle src = (XSSFCellStyle)source; // Is it on our Workbook? if (src._stylesSource == _stylesSource) { // Nice and easy _cellXf = src.GetCoreXf(); _cellStyleXf = src.GetStyleXf(); } else { // Copy the style try { // Remove any children off the current style, to // avoid orphaned nodes if (_cellXf.IsSetAlignment()) { _cellXf.UnsetAlignment(); } if (_cellXf.IsSetExtLst()) { _cellXf.UnsetExtLst(); } // Create a new Xf with the same contents _cellXf = CT_Xf.Parse( src.GetCoreXf().ToString() ); // Swap it over _stylesSource.ReplaceCellXfAt(_cellXfId, _cellXf); } catch (XmlException e) { throw new POIXMLException(e); } // Copy the format String fmt = src.GetDataFormatString(); DataFormat = ( (new XSSFDataFormat(_stylesSource)).GetFormat(fmt) ); // Copy the font try { CT_Font ctFont = CT_Font.Parse( src.GetFont().GetCTFont().ToString() ); XSSFFont font = new XSSFFont(ctFont); font.RegisterTo(_stylesSource); SetFont(font); } catch (XmlException e) { throw new POIXMLException(e); } } // Clear out cached details _font = null; _cellAlignment = null; } else { throw new ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle"); } }
/** * Clones all the style information from another * XSSFCellStyle, onto this one. This * XSSFCellStyle will then have all the same * properties as the source, but the two may * be edited independently. * Any stylings on this XSSFCellStyle will be lost! * * The source XSSFCellStyle could be from another * XSSFWorkbook if you like. This allows you to * copy styles from one XSSFWorkbook to another. */ public void CloneStyleFrom(ICellStyle source) { if (source is XSSFCellStyle) { XSSFCellStyle src = (XSSFCellStyle)source; // Is it on our Workbook? if (src._stylesSource == _stylesSource) { // Nice and easy _cellXf = src.GetCoreXf().Copy(); _cellStyleXf = src.GetStyleXf().Copy(); } else { // Copy the style try { // Remove any children off the current style, to // avoid orphaned nodes if (_cellXf.IsSetAlignment()) { _cellXf.UnsetAlignment(); } if (_cellXf.IsSetExtLst()) { _cellXf.UnsetExtLst(); } // Create a new Xf with the same contents _cellXf = src.GetCoreXf().Copy(); if (_cellXf.applyBorder) { //CellXF is copied with existing Ids, but those are different if you're copying between two documents _cellXf.borderId = FindAddBorder(src._stylesSource.GetBorderAt((int)_cellXf.borderId).GetCTBorder()); } // bug 56295: ensure that the fills is available and set correctly CT_Fill fill = CT_Fill.Parse(src.GetCTFill().ToString()); AddFill(fill); if (src._cellStyleXf.applyBorder) { _cellStyleXf.borderId = FindAddBorder(src.GetCTBorder()); } // Swap it over _stylesSource.ReplaceCellXfAt(_cellXfId, _cellXf); } catch (XmlException e) { throw new POIXMLException(e); } // Copy the format String fmt = src.GetDataFormatString(); DataFormat = ( (new XSSFDataFormat(_stylesSource)).GetFormat(fmt) ); // Copy the font try { CT_Font ctFont = src.GetFont().GetCTFont().Clone(); XSSFFont font = new XSSFFont(ctFont); font.RegisterTo(_stylesSource); SetFont(font); } catch (XmlException e) { throw new POIXMLException(e); } } // Clear out cached details _font = null; _cellAlignment = null; } else { throw new ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle"); } }
private void CheckStyle(XSSFCellStyle cellStyle) { Assert.IsNotNull(cellStyle); Assert.AreEqual(0, cellStyle.FillForegroundColor); Assert.IsNotNull(cellStyle.FillForegroundXSSFColor); XSSFColor fgColor = cellStyle.FillForegroundColorColor as XSSFColor; Assert.IsNotNull(fgColor); Assert.AreEqual("FF00FFFF", fgColor.GetARGBHex()); Assert.AreEqual(0, cellStyle.FillBackgroundColor); Assert.IsNotNull(cellStyle.FillBackgroundXSSFColor); XSSFColor bgColor = cellStyle.FillBackgroundColorColor as XSSFColor; Assert.IsNotNull(bgColor); Assert.AreEqual("FF00FFFF", fgColor.GetARGBHex()); }