/** * Initialize a new Speadsheet VML Drawing */ private void newDrawing() { CT_ShapeLayout layout = new CT_ShapeLayout(); layout.ext = (ST_Ext.edit); CT_IdMap idmap = layout.AddNewIdmap(); idmap.ext = (ST_Ext.edit); idmap.data = ("1"); _items.Add(layout); CT_Shapetype shapetype = new CT_Shapetype(); _shapeTypeId = COMMENT_SHAPE_TYPE_ID; shapetype.id = _shapeTypeId;// "_x0000_t" + _shapeTypeId; shapetype.coordsize = "21600,21600"; shapetype.spt = 202; //_shapeTypeId = 202; shapetype.path2 = ("m,l,21600r21600,l21600,xe"); shapetype.AddNewStroke().joinstyle = (ST_StrokeJoinStyle.miter); CT_Path path = shapetype.AddNewPath(); path.gradientshapeok = NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t; path.connecttype = (ST_ConnectType.rect); _items.Add(shapetype); }
/** * Initialize a new Speadsheet VML Drawing */ private void newDrawing() { CT_ShapeLayout layout = new CT_ShapeLayout(); layout.ext = (ST_Ext.edit); CT_IdMap idmap = layout.AddNewIdmap(); idmap.ext = (ST_Ext.edit); idmap.data = ("1"); _items.Add(layout); CT_Shapetype shapetype = new CT_Shapetype(); _shapeTypeId = "_xssf_cell_comment"; shapetype.id = _shapeTypeId; shapetype.coordsize = "21600,21600"; shapetype.spt = 202; shapetype.path2 = ("m,l,21600r21600,l21600,xe"); shapetype.AddNewStroke().joinstyle = (ST_StrokeJoinStyle.miter); CT_Path path = shapetype.AddNewPath(); path.gradientshapeok = ST_TrueFalse.t; path.connecttype = (ST_ConnectType.rect); _items.Add(shapetype); }
private void newDrawing() { CT_ShapeLayout ctShapeLayout = new CT_ShapeLayout(); ctShapeLayout.ext = ST_Ext.edit; CT_IdMap ctIdMap = ctShapeLayout.AddNewIdmap(); ctIdMap.ext = ST_Ext.edit; ctIdMap.data = "1"; this._items.Add((object)ctShapeLayout); CT_Shapetype ctShapetype = new CT_Shapetype(); this._shapeTypeId = "_xssf_cell_comment"; ctShapetype.id = this._shapeTypeId; ctShapetype.coordsize = "21600,21600"; ctShapetype.spt = 202f; ctShapetype.path2 = "m,l,21600r21600,l21600,xe"; ctShapetype.AddNewStroke().joinstyle = ST_StrokeJoinStyle.miter; CT_Path ctPath = ctShapetype.AddNewPath(); ctPath.gradientshapeok = ST_TrueFalse.t; ctPath.connecttype = ST_ConnectType.rect; this._items.Add((object)ctShapetype); }
private static void CreateWaterMark(XWPFDocument doc, string headerText, string imageUrl = null) { if (doc.Document.body.sectPr == null) { doc.Document.body.sectPr = new CT_SectPr(); } CT_SectPr m_SectPr = doc.Document.body.sectPr; CT_Hdr header = new CT_Hdr(); //header.AddNewP().AddNewR().AddNewT().Value = headerText; var paragraph = header.AddNewP(); var ppr = paragraph.AddNewPPr(); ppr.AddNewPStyle().val = "a3"; ppr.AddNewJc().val = ST_Jc.right; var r = paragraph.AddNewR(); r.AddNewRPr().AddNewNoProof(); CT_Picture pict = r.AddNewPict(); CT_Shapetype shapetype = new CT_Shapetype(); shapetype.id = ("_x0000_t136"); shapetype.coordsize = ("21600,21600"); shapetype.spt = (136); shapetype.adj = ("10800"); shapetype.path2 = ("m@7,0l@8,0m@5,21600l@6,21600e"); CT_Formulas formulas = shapetype.AddNewFormulas(); formulas.AddNewF().eqn = ("sum #0 0 10800"); formulas.AddNewF().eqn = ("prod #0 2 1"); formulas.AddNewF().eqn = ("sum 21600 0 @1"); formulas.AddNewF().eqn = ("sum 0 0 @2"); formulas.AddNewF().eqn = ("sum 21600 0 @3"); formulas.AddNewF().eqn = ("if @0 @3 0"); formulas.AddNewF().eqn = ("if @0 21600 @1"); formulas.AddNewF().eqn = ("if @0 0 @2"); formulas.AddNewF().eqn = ("if @0 @4 21600"); formulas.AddNewF().eqn = ("mid @5 @6"); formulas.AddNewF().eqn = ("mid @8 @5"); formulas.AddNewF().eqn = ("mid @7 @8"); formulas.AddNewF().eqn = ("mid @6 @7"); formulas.AddNewF().eqn = ("sum @6 0 @5"); CT_Path path = shapetype.AddNewPath(); path.textpathok = (NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t); path.connecttype = (NPOI.OpenXmlFormats.Vml.Office.ST_ConnectType.custom); path.connectlocs = ("@9,0;@10,10800;@11,21600;@12,10800"); path.connectangles = ("270,180,90,0"); CT_TextPath shapeTypeTextPath = shapetype.AddNewTextpath(); shapeTypeTextPath.on = (NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t); shapeTypeTextPath.fitshape = (NPOI.OpenXmlFormats.Vml.ST_TrueFalse.t); CT_Handles handles = shapetype.AddNewHandles(); CT_H h = handles.AddNewH(); h.position = ("#0,bottomRight"); h.xrange = ("6629,14971"); NPOI.OpenXmlFormats.Vml.Office.CT_Lock lock1 = shapetype.AddNewLock(); lock1.ext = (ST_Ext.edit); lock1.text = NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.t; lock1.shapetype = NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.t; CT_Shape shape = new CT_Shape(); shape.id = ("PowerPlusWaterMarkObject" + "1109904797"); shape.spid = ("_x0000_s206" + (4 + "1")); shape.type = ("#_x0000_t136"); shape.style = ("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin"); //shape.wrapcoords = ("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068"); shape.fillcolor = ("#ed7d31 [3205]"); shape.stroked = (NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false); shape.AddNewFill().opacity = ".5"; CT_TextPath shapeTextPath = shape.AddNewTextpath(); shapeTextPath.style = ("font-family:"Yu Gothic UI""); shapeTextPath.@string = ("吴润杰水印"); // pict.Items.Add(shapetype); //pict.Set(shapetype); pict.Set(shape); //pict.Set(group); XWPFRelation Hrelation = XWPFRelation.HEADER; XWPFHeader docHeader = (XWPFHeader)doc.CreateRelationship(Hrelation, XWPFFactory.GetInstance(), doc.HeaderList.Count); docHeader.SetXWPFDocument(doc); //设置页眉 docHeader.SetHeaderFooter(header); CT_HdrFtrRef m_HdrFtr2 = m_SectPr.AddNewHeaderReference(); m_HdrFtr2.type = ST_HdrFtr.@default; m_HdrFtr2.id = docHeader.GetPackageRelationship().Id; }
/* * This is the default Watermark paragraph; the only variable is the text message * TODO: manage all the other variables */ private XWPFParagraph GetWatermarkParagraph(String text, int idx) { CT_P p = new CT_P(); byte[] rsidr = doc.Document.body.GetPArray(0).rsidR; byte[] rsidrdefault = doc.Document.body.GetPArray(0).rsidRDefault; p.rsidP = (rsidr); p.rsidRDefault = (rsidrdefault); CT_PPr pPr = p.AddNewPPr(); pPr.AddNewPStyle().val = ("Header"); // start watermark paragraph Npoi.Core.OpenXmlFormats.Wordprocessing.CT_R r = p.AddNewR(); CT_RPr rPr = r.AddNewRPr(); rPr.AddNewNoProof(); CT_Picture pict = r.AddNewPict(); CT_Group group = new CT_Group(); CT_Shapetype shapetype = group.AddNewShapetype(); shapetype.id = ("_x0000_t136"); shapetype.coordsize = ("1600,21600"); shapetype.spt = (136); shapetype.adj = ("10800"); shapetype.path2 = ("m@7,0l@8,0m@5,21600l@6,21600e"); CT_Formulas formulas = shapetype.AddNewFormulas(); formulas.AddNewF().eqn = ("sum #0 0 10800"); formulas.AddNewF().eqn = ("prod #0 2 1"); formulas.AddNewF().eqn = ("sum 21600 0 @1"); formulas.AddNewF().eqn = ("sum 0 0 @2"); formulas.AddNewF().eqn = ("sum 21600 0 @3"); formulas.AddNewF().eqn = ("if @0 @3 0"); formulas.AddNewF().eqn = ("if @0 21600 @1"); formulas.AddNewF().eqn = ("if @0 0 @2"); formulas.AddNewF().eqn = ("if @0 @4 21600"); formulas.AddNewF().eqn = ("mid @5 @6"); formulas.AddNewF().eqn = ("mid @8 @5"); formulas.AddNewF().eqn = ("mid @7 @8"); formulas.AddNewF().eqn = ("mid @6 @7"); formulas.AddNewF().eqn = ("sum @6 0 @5"); CT_Path path = shapetype.AddNewPath(); path.textpathok = (Npoi.Core.OpenXmlFormats.Vml.ST_TrueFalse.t); path.connecttype = (ST_ConnectType.custom); path.connectlocs = ("@9,0;@10,10800;@11,21600;@12,10800"); path.connectangles = ("270,180,90,0"); CT_TextPath shapeTypeTextPath = shapetype.AddNewTextpath(); shapeTypeTextPath.on = (Npoi.Core.OpenXmlFormats.Vml.ST_TrueFalse.t); shapeTypeTextPath.fitshape = (Npoi.Core.OpenXmlFormats.Vml.ST_TrueFalse.t); CT_Handles handles = shapetype.AddNewHandles(); CT_H h = handles.AddNewH(); h.position = ("#0,bottomRight"); h.xrange = ("6629,14971"); Npoi.Core.OpenXmlFormats.Vml.Office.CT_Lock lock1 = shapetype.AddNewLock(); lock1.ext = (ST_Ext.edit); CT_Shape shape = group.AddNewShape(); shape.id = ("PowerPlusWaterMarkObject" + idx); shape.spid = ("_x0000_s102" + (4 + idx)); shape.type = ("#_x0000_t136"); shape.style = ("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin"); shape.wrapcoords = ("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068"); shape.fillcolor = ("black"); shape.stroked = (Npoi.Core.OpenXmlFormats.Vml.ST_TrueFalse.@false); CT_TextPath shapeTextPath = shape.AddNewTextpath(); shapeTextPath.style = ("font-family:"Cambria";font-size:1pt"); shapeTextPath.@string = (text); pict.Set(group); // end watermark paragraph return(new XWPFParagraph(p, doc)); }
private XWPFParagraph GetWatermarkParagraph(string text, int idx) { CT_P prgrph = new CT_P(); byte[] rsidR = this.doc.Document.body.GetPArray(0).rsidR; byte[] rsidRdefault = this.doc.Document.body.GetPArray(0).rsidRDefault; prgrph.rsidP = rsidR; prgrph.rsidRDefault = rsidRdefault; prgrph.AddNewPPr().AddNewPStyle().val = "Header"; NPOI.OpenXmlFormats.Wordprocessing.CT_R ctR = prgrph.AddNewR(); ctR.AddNewRPr().AddNewNoProof(); CT_Picture ctPicture = ctR.AddNewPict(); CT_Group ctGroup = new CT_Group(); CT_Shapetype ctShapetype = ctGroup.AddNewShapetype(); ctShapetype.id = "_x0000_t136"; ctShapetype.coordsize = "1600,21600"; ctShapetype.spt = 136f; ctShapetype.adj = "10800"; ctShapetype.path2 = "m@7,0l@8,0m@5,21600l@6,21600e"; CT_Formulas ctFormulas = ctShapetype.AddNewFormulas(); ctFormulas.AddNewF().eqn = "sum #0 0 10800"; ctFormulas.AddNewF().eqn = "prod #0 2 1"; ctFormulas.AddNewF().eqn = "sum 21600 0 @1"; ctFormulas.AddNewF().eqn = "sum 0 0 @2"; ctFormulas.AddNewF().eqn = "sum 21600 0 @3"; ctFormulas.AddNewF().eqn = "if @0 @3 0"; ctFormulas.AddNewF().eqn = "if @0 21600 @1"; ctFormulas.AddNewF().eqn = "if @0 0 @2"; ctFormulas.AddNewF().eqn = "if @0 @4 21600"; ctFormulas.AddNewF().eqn = "mid @5 @6"; ctFormulas.AddNewF().eqn = "mid @8 @5"; ctFormulas.AddNewF().eqn = "mid @7 @8"; ctFormulas.AddNewF().eqn = "mid @6 @7"; ctFormulas.AddNewF().eqn = "sum @6 0 @5"; CT_Path ctPath = ctShapetype.AddNewPath(); ctPath.textpathok = ST_TrueFalse.t; ctPath.connecttype = ST_ConnectType.custom; ctPath.connectlocs = "@9,0;@10,10800;@11,21600;@12,10800"; ctPath.connectangles = "270,180,90,0"; CT_TextPath ctTextPath1 = ctShapetype.AddNewTextpath(); ctTextPath1.on = ST_TrueFalse.t; ctTextPath1.fitshape = ST_TrueFalse.t; CT_H ctH = ctShapetype.AddNewHandles().AddNewH(); ctH.position = "#0,bottomRight"; ctH.xrange = "6629,14971"; ctShapetype.AddNewLock().ext = ST_Ext.edit; CT_Shape ctShape = ctGroup.AddNewShape(); ctShape.id = "PowerPlusWaterMarkObject" + (object)idx; ctShape.spid = "_x0000_s102" + (object)(4 + idx); ctShape.type = "#_x0000_t136"; ctShape.style = "position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin"; ctShape.wrapcoords = "616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068"; ctShape.fillcolor = "black"; ctShape.stroked = ST_TrueFalse.@false; CT_TextPath ctTextPath2 = ctShape.AddNewTextpath(); ctTextPath2.style = "font-family:"Cambria";font-size:1pt"; ctTextPath2.@string = text; ctPicture.Set((object)ctGroup); return(new XWPFParagraph(prgrph, (IBody)this.doc)); }