public void TestGetFillPattern() { //??? //assertEquals(STPatternType.INT_DARK_GRAY-1, cellStyle.getFillPattern()); Assert.AreEqual((int)ST_PatternType.darkGray, (int)cellStyle.FillPattern); int num = stylesTable.GetFills().Count; cellStyle.FillPattern = (FillPattern.SolidForeground); Assert.AreEqual(FillPattern.SolidForeground, cellStyle.FillPattern); Assert.AreEqual(num + 1, stylesTable.GetFills().Count); int FillId = (int)cellStyle.GetCoreXf().fillId; Assert.IsTrue(FillId > 0); //check Changes in the underlying xml bean CT_Fill ctFill = stylesTable.GetFillAt(FillId).GetCTFill(); Assert.AreEqual(ST_PatternType.solid, ctFill.GetPatternFill().patternType); //setting the same fill multiple time does not update the styles table for (int i = 0; i < 3; i++) { cellStyle.FillPattern = (FillPattern.SolidForeground); } Assert.AreEqual(num + 1, stylesTable.GetFills().Count); cellStyle.FillPattern = (FillPattern.NoFill); Assert.AreEqual(FillPattern.NoFill, cellStyle.FillPattern); FillId = (int)cellStyle.GetCoreXf().fillId; ctFill = stylesTable.GetFillAt(FillId).GetCTFill(); Assert.IsFalse(ctFill.GetPatternFill().IsSetPatternType()); }
public XMLFillModel DeepClone() { CT_Fill cT_Fill = new CT_Fill(); if (this._fill.PatternFill != null) { CT_PatternFill patternFill = this._fill.PatternFill; CT_PatternFill cT_PatternFill2 = cT_Fill.PatternFill = new CT_PatternFill(); if (patternFill.BgColor != null) { cT_PatternFill2.BgColor = this._palette.GetColorFromCT(patternFill.BgColor).Clone().Data; } if (patternFill.FgColor != null) { cT_PatternFill2.FgColor = this._palette.GetColorFromCT(patternFill.FgColor).Clone().Data; } cT_PatternFill2.PatternType_Attr = patternFill.PatternType_Attr; } cT_Fill.Choice_0 = this._fill.Choice_0; XMLFillModel xMLFillModel = new XMLFillModel(cT_Fill, this._palette); if (this._background != null) { xMLFillModel._background = this._background.Clone(); } if (this._foreground != null) { xMLFillModel._foreground = this._foreground.Clone(); } return(xMLFillModel); }
private void AddFill(CT_Fill fill) { int idx = _stylesSource.PutFill(new XSSFCellFill(fill)); _cellXf.fillId = (uint)(idx); _cellXf.applyFill = (true); }
/** * Set the foreground fill color represented as a {@link XSSFColor} value. * <br/> * <i>Note: Ensure Foreground color is Set prior to background color.</i> * @param color the color to use * @see #setFillBackgroundColor(Npoi.Core.xssf.usermodel.XSSFColor) ) */ public void SetFillForegroundColor(XSSFColor color) { CT_Fill ct = GetCTFill(); CT_PatternFill ptrn = ct.GetPatternFill(); if (color == null) { if (ptrn != null) { ptrn.UnsetFgColor(); } } else { if (ptrn == null) { ptrn = ct.AddNewPatternFill(); } ptrn.fgColor = (color.GetCTColor()); } int idx = _stylesSource.PutFill(new XSSFCellFill(ct)); _cellXf.fillId = (uint)idx; _cellXf.applyFill = (true); }
public void TestGetFillPattern() { Assert.AreEqual(FillPatternType.NO_FILL, cellStyle.FillPattern); int num = stylesTable.GetFills().Count; cellStyle.FillPattern = (FillPatternType.SOLID_FOREGROUND); Assert.AreEqual(FillPatternType.SOLID_FOREGROUND, cellStyle.FillPattern); Assert.AreEqual(num + 1, stylesTable.GetFills().Count); int FillId = (int)cellStyle.GetCoreXf().fillId; Assert.IsTrue(FillId > 0); //check Changes in the underlying xml bean CT_Fill ctFill = stylesTable.GetFillAt(FillId).GetCTFill(); Assert.AreEqual(ST_PatternType.solid, ctFill.GetPatternFill().patternType); //setting the same fill multiple time does not update the styles table for (int i = 0; i < 3; i++) { cellStyle.FillPattern = (FillPatternType.SOLID_FOREGROUND); } Assert.AreEqual(num + 1, stylesTable.GetFills().Count); cellStyle.FillPattern = (FillPatternType.NO_FILL); Assert.AreEqual(FillPatternType.NO_FILL, cellStyle.FillPattern); FillId = (int)cellStyle.GetCoreXf().fillId; ctFill = stylesTable.GetFillAt(FillId).GetCTFill(); Assert.IsFalse(ctFill.GetPatternFill().IsSetPatternType()); }
private static CT_Fill[] CreateDefaultFills() { CT_Fill[] ctFill = new CT_Fill[] { new CT_Fill(), new CT_Fill() }; ctFill[0].AddNewPatternFill().patternType = (ST_PatternType.none); ctFill[1].AddNewPatternFill().patternType = (ST_PatternType.darkGray); return(ctFill); }
public XMLFillModel(XMLPaletteModel palette) { this._fill = new CT_Fill(); this._fill.Choice_0 = CT_Fill.ChoiceBucket_0.patternFill; this._fill.PatternFill = new CT_PatternFill(); this._fill.PatternFill.PatternType_Attr = ST_PatternType.none; this._palette = palette; }
public void TestGetSetPatternType() { CT_Fill ctFill = new CT_Fill(); XSSFCellFill cellFill = new XSSFCellFill(ctFill); CT_PatternFill ctPatternFill = ctFill.AddNewPatternFill(); ctPatternFill.patternType = (ST_PatternType.solid); Assert.AreEqual(ST_PatternType.solid, cellFill.GetPatternType()); }
private static CT_Fill[] CreateDefaultFills() { CT_Fill[] ctFillArray = new CT_Fill[2] { new CT_Fill(), new CT_Fill() }; ctFillArray[0].AddNewPatternFill().patternType = ST_PatternType.none; ctFillArray[1].AddNewPatternFill().patternType = ST_PatternType.darkGray; return(ctFillArray); }
public void TestGetNotModifies() { CT_Fill ctFill = new CT_Fill(); XSSFCellFill cellFill = new XSSFCellFill(ctFill); CT_PatternFill ctPatternFill = ctFill.AddNewPatternFill(); ctPatternFill.patternType = (ST_PatternType.darkDown); Assert.AreEqual(ST_PatternType.darkDown, cellFill.GetPatternType()); }
public void TestGetFillForegroundColor() { CT_Fill ctFill = new CT_Fill(); XSSFCellFill cellFill = new XSSFCellFill(ctFill); CT_PatternFill ctPatternFill = ctFill.AddNewPatternFill(); CT_Color fgColor = ctPatternFill.AddNewFgColor(); Assert.IsNotNull(cellFill.GetFillForegroundColor()); fgColor.indexed = 8; fgColor.indexedSpecified = true; Assert.AreEqual(8, cellFill.GetFillForegroundColor().Indexed); }
public XMLFillModel(CT_Fill fill, XMLPaletteModel palette) { this._fill = fill; this._palette = palette; if (this._fill.PatternFill != null) { if (this._fill.PatternFill.FgColor != null) { this._foreground = this._palette.GetColorFromCT(this._fill.PatternFill.FgColor); } if (this._fill.PatternFill.BgColor != null) { this._background = this._palette.GetColorFromCT(this._fill.PatternFill.BgColor); } } }
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); }
/** * Get a <b>copy</b> of the currently used CT_Fill, if none is used, return a new instance. */ private CT_Fill GetCTFill() { CT_Fill ct; if (_cellXf.applyFill) { int FillIndex = (int)_cellXf.fillId; XSSFCellFill cf = _stylesSource.GetFillAt(FillIndex); ct = (CT_Fill)cf.GetCTFill().Copy(); } else { ct = new CT_Fill(); } return(ct); }
private CellFill ConvertDxfCellFill(CT_Fill ct_fill) { CT_PatternFill pf; var cellFill = new CellFill(); if (Util.TryCast(ct_fill.Item, out pf)) { cellFill.Background = ConvertColor(pf.bgColor); cellFill.Foreground = ConvertColor(pf.fgColor); if (pf.patternType == ST_PatternType.none) { pf.patternType = ST_PatternType.solid; } cellFill.Pattern = (FillPattern)pf.patternType; } return(cellFill); }
/** * Get a <b>copy</b> of the currently used CT_Fill, if none is used, return a new instance. */ public CT_Fill GetCTFill() { CT_Fill ct; // bug 56295: handle missing applyFill attribute as "true" because Excel does as well if (!_cellXf.IsSetApplyFill() || _cellXf.applyFill) { int FillIndex = (int)_cellXf.fillId; XSSFCellFill cf = _stylesSource.GetFillAt(FillIndex); ct = (CT_Fill)cf.GetCTFill().Copy(); } else { ct = new CT_Fill(); } return(ct); }
public void TestGetSetFillBackgroundColor() { Assert.AreEqual(IndexedColors.Automatic.Index, cellStyle.FillBackgroundColor); Assert.IsNull(cellStyle.FillBackgroundColorColor); XSSFColor clr; int num = stylesTable.GetFills().Count; //setting indexed color cellStyle.FillBackgroundColor = (IndexedColors.Red.Index); Assert.AreEqual(IndexedColors.Red.Index, cellStyle.FillBackgroundColor); clr = (XSSFColor)cellStyle.FillBackgroundColorColor; Assert.IsTrue(clr.GetCTColor().IsSetIndexed()); Assert.AreEqual(IndexedColors.Red.Index, clr.Indexed); //a new fill was Added to the styles table Assert.AreEqual(num + 1, stylesTable.GetFills().Count); //id of the Created border int FillId = (int)cellStyle.GetCoreXf().fillId; Assert.IsTrue(FillId > 0); //check changes in the underlying xml bean CT_Fill ctFill = stylesTable.GetFillAt(FillId).GetCTFill(); Assert.AreEqual((uint)IndexedColors.Red.Index, ctFill.GetPatternFill().bgColor.indexed); //setting XSSFColor num = stylesTable.GetFills().Count; clr = new XSSFColor(Color.Cyan); cellStyle.SetFillBackgroundColor(clr); // TODO this testcase assumes that cellStyle creates a new CT_Fill, but the implementation changes the existing style. - do not know whats right 8-( Assert.AreEqual(clr.GetCTColor().ToString(), ((XSSFColor)cellStyle.FillBackgroundColorColor).GetCTColor().ToString()); byte[] rgb = ((XSSFColor)cellStyle.FillBackgroundColorColor).RGB; Assert.AreEqual(Color.Cyan, Color.FromRgb((byte)(rgb[0] & 0xFF), (byte)(rgb[1] & 0xFF), (byte)(rgb[2] & 0xFF))); //another border was added to the styles table Assert.AreEqual(num + 1, stylesTable.GetFills().Count); //passing null unsets the color cellStyle.SetFillBackgroundColor(null); Assert.IsNull(cellStyle.FillBackgroundColorColor); Assert.AreEqual(IndexedColors.Automatic.Index, cellStyle.FillBackgroundColor); }
public void SetFillForegroundColor(XSSFColor color) { CT_Fill ctFill = this.GetCTFill(); CT_PatternFill ctPatternFill = ctFill.GetPatternFill(); if (color == null) { ctPatternFill?.unsetFgColor(); } else { if (ctPatternFill == null) { ctPatternFill = ctFill.AddNewPatternFill(); } ctPatternFill.fgColor = color.GetCTColor(); } this._cellXf.fillId = (uint)this._stylesSource.PutFill(new XSSFCellFill(ctFill)); this._cellXf.applyFill = true; }
public XSSFCellFill(CT_Fill Fill) { this._fill = Fill; }
public PartManager(XMLWorkbookModel workbookModel) { _workbookmodel = workbookModel; _relationshipTree = new OPCRelationshipTree("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", ((IStreambookModel)_workbookmodel).ZipPackage); WorkbookPart workbookPart = new WorkbookPart(); CT_Workbook obj = (CT_Workbook)workbookPart.Root; obj.FileVersion = new CT_FileVersion(); obj.FileVersion.AppName_Attr = "xl"; obj.FileVersion.LastEdited_Attr = "4"; obj.FileVersion.LowestEdited_Attr = "4"; obj.FileVersion.RupBuild_Attr = "4506"; obj.WorkbookPr = new CT_WorkbookPr(); obj.WorkbookPr.DefaultThemeVersion_Attr = 124226u; obj.BookViews = new CT_BookViews(); CT_BookView item = new CT_BookView { XWindow_Attr = 240, YWindow_Attr = 120, WindowWidth_Attr = 18060u, WindowHeight_Attr = 7050u }; obj.BookViews.WorkbookView.Add(item); obj.CalcPr = new CT_CalcPr(); obj.CalcPr.CalcId_Attr = 125725u; Relationship relationship = _relationshipTree.AddRootPartToTree(workbookPart, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "xl/workbook.xml"); _workbook = workbookPart; StyleSheetPart styleSheetPart = new StyleSheetPart(); CT_Stylesheet obj2 = (CT_Stylesheet)styleSheetPart.Root; CT_Font cT_Font = new CT_Font(); cT_Font.Sz = new CT_FontSize(); cT_Font.Sz.Val_Attr = 11.0; cT_Font.Color = new CT_Color(); cT_Font.Color.Rgb_Attr = "FF000000"; cT_Font.Name = new CT_FontName(); cT_Font.Name.Val_Attr = "Calibri"; cT_Font.Family = new CT_IntProperty(); cT_Font.Family.Val_Attr = 2; cT_Font.Scheme = new CT_FontScheme(); cT_Font.Scheme.Val_Attr = ST_FontScheme.minor; obj2.Fonts = new CT_Fonts(); obj2.Fonts.Font.Add(cT_Font); obj2.Fonts.Count_Attr = 1u; CT_Fill cT_Fill = new CT_Fill(); cT_Fill.PatternFill = new CT_PatternFill(); cT_Fill.PatternFill.PatternType_Attr = ST_PatternType.none; CT_Fill cT_Fill2 = new CT_Fill(); cT_Fill2.PatternFill = new CT_PatternFill(); cT_Fill2.PatternFill.PatternType_Attr = ST_PatternType.gray125; obj2.Fills = new CT_Fills(); obj2.Fills.Fill.Add(cT_Fill); obj2.Fills.Fill.Add(cT_Fill2); obj2.Fills.Count_Attr = 2u; CT_Border item2 = new CT_Border { Left = new CT_BorderPr(), Right = new CT_BorderPr(), Top = new CT_BorderPr(), Bottom = new CT_BorderPr(), Diagonal = new CT_BorderPr() }; obj2.Borders = new CT_Borders(); obj2.Borders.Border.Add(item2); obj2.Borders.Count_Attr = 1u; CT_Xf item3 = new CT_Xf { NumFmtId_Attr = 0u, FontId_Attr = 0u, FillId_Attr = 0u, BorderId_Attr = 0u }; obj2.CellStyleXfs = new CT_CellStyleXfs(); obj2.CellStyleXfs.Xf.Add(item3); obj2.CellXfs = new CT_CellXfs(); obj2.CellXfs.Xf.Add(StyleManager.CreateDefaultXf()); CT_CellStyle item4 = new CT_CellStyle { Name_Attr = "Normal", XfId_Attr = 0u, BuiltinId_Attr = 0u }; obj2.CellStyles = new CT_CellStyles(); obj2.CellStyles.CellStyle.Add(item4); obj2.Dxfs = new CT_Dxfs(); obj2.Dxfs.Count_Attr = 0u; obj2.TableStyles = new CT_TableStyles(); obj2.TableStyles.Count_Attr = 0u; obj2.TableStyles.DefaultTableStyle_Attr = "TableStyleMedium9"; obj2.TableStyles.DefaultPivotStyle_Attr = "PivotStyleLight16"; _relationshipTree.AddPartToTree(styleSheetPart, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "xl/styles.xml", (XmlPart)_relationshipTree.GetPartByLocation(relationship.RelatedPart)); _stylesheet = new StyleManager(styleSheetPart); OpcCorePropertiesPart part = new OpcCorePropertiesPart(); _relationshipTree.AddRootPartToTree(part, "application/vnd.openxmlformats-package.core-properties+xml", "http://schemas.openxmlformats.org/package/2006/relationships/meatadata/core-properties", "docProps/core.xml"); PropertiesPart propertiesPart = new PropertiesPart(); CT_Properties obj3 = (CT_Properties)propertiesPart.Root; obj3.Application = "Microsoft Excel"; obj3.DocSecurity = 0; obj3.ScaleCrop = false; obj3.HeadingPairs = new CT_VectorVariant(); obj3.HeadingPairs.Vector = new CT_Vector(); obj3.HeadingPairs.Vector.Size_Attr = 2u; obj3.HeadingPairs.Vector.BaseType_Attr = ST_VectorBaseType.variant; CT_Variant item5 = new CT_Variant { Choice_0 = CT_Variant.ChoiceBucket_0.lpstr, Lpstr = "Worksheets" }; CT_Variant item6 = new CT_Variant { Choice_0 = CT_Variant.ChoiceBucket_0.i4, I4 = 1 }; obj3.HeadingPairs.Vector.Variant.Add(item5); obj3.HeadingPairs.Vector.Variant.Add(item6); obj3.TitlesOfParts = new CT_VectorLpstr(); obj3.TitlesOfParts.Vector = new CT_Vector(); obj3.TitlesOfParts.Vector.Size_Attr = 0u; obj3.TitlesOfParts.Vector.BaseType_Attr = ST_VectorBaseType.lpstr; obj3.LinksUpToDate = false; obj3.SharedDoc = false; obj3.HyperlinksChanged = false; obj3.AppVersion = "12.0000"; _relationshipTree.AddRootPartToTree(propertiesPart, "application/vnd.openxmlformats-officedocument.extended-properties+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml"); }
/** * 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(); // bug 56295: ensure that the fills is available and set correctly CT_Fill fill = CT_Fill.Parse(src.GetCTFill().ToString()); AddFill(fill); // 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"); } }
/** * Creates a CellFill from the supplied parts * * @param fill - fill */ public XSSFCellFill(CT_Fill fill) { _fill = fill; }
/** * Creates an empty CellFill */ public XSSFCellFill() { _fill = new CT_Fill(); }
public XSSFPatternFormatting(CT_Fill fill) { _fill = fill; }
public XSSFCellFill() { this._fill = new CT_Fill(); }