c# - Export Datatable to Word Document With Page Numbers using Open XML -


I need: Exporting a dynamic data tile in Word document with the word number We use Open XML to get it Have to do. I have code to export datatize to the word i and also to insert page number

I Code was exported to datatable

  public void CreateWordtable (string filename, DataTable data) {WordprocessingDocument Dock = WordprocessingDocument.Create (filename, word processing Dokyumenttaip down .doc); MainDocumentPart main document page = doc.AddMainDocumentPart (); MainDocPart.Document = new document (); Body of body = new body (); MainDocPart.Document.Append (body); // rinks @: document forming new table form.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table (); For (int i = 0; i & lt; data.ropecount; ++ i) {table row = new tabler (); For (int j = 0; j and lt; data columns; calculation; j ++) {table cell cell = new tablecase (); CellkAppend (new paragraph (new DocumentFormatkOpenXmlkWordprocessingkRun (New DocumentFormat.OpenXml.Wordprocessing.Text (data.Rows [i] [j] .ToString ())))); Cell. Append (new tableclass properties (new tablecloths {type = tablewind unit value.dxa, width = "1200"})); Row.Append (cell); } Table. Append (line); } Body.Append (table); Doc.MainDocumentPart.Document.Save (); Doc.Dispose (); }  

and a word in the code below is to insert the page number in the document

  Private static Zero AddPageNumberFooters (WordprocessingDocument parent) { String documentPath = @ "D: \ EmptyDoc.docx"; (Using the wordprocessing document package = wordprogging document.open (document path, true)) {var mainDocumentPart = parent.AddMainDocumentPart (); . Save GenerateMainDocumentPart () (mainDocumentPart); Var documentSettingsPart = mainDocumentPart.AddNewPart & lt; DocumentSettingsPart & gt; ("RId1"); . Save GenerateDocumentSettingsPart () (documentSettingsPart); Var first pagefootpart = main download page AddNewPart & lt; FooterPart & gt; ("RID1"); GeneratePageFooterPart ("Page 1 of 1"). Save (First PageFooterParty); Var seconds pagefuterpart = main documentpart.adnepart & lt; FooterPart & gt; ("RID 2"); GeneratePageFooterPart ("2 of 2"). Save (second pagefuterpart); }} Private static document generated Krenmandokyumentpart () {var element = new Document (new body (new paragraph (new part (new text ( "New Page" (New Page) (new text (new section) KPage})), new article (new run (new LastRenderedPageBreak (), the new text ( "page 2 content"))), new paragraph (new runs (new break () {type = BreakValues.Page})), a new section properties (new footer) (Type = headerfooter value.First, id = "RID1"}, new footer () {type = HeaderFooterValues.Even, id = "rId2"}, no PageMargin () {top = 1440, Wright = (UInt32Value) 1440UL, down = 1440, Left = (UInt32Value) 1440UL, header = (UInt32Value) 720UL, footer = (UInt32Value) 720UL, gutter = (UInt32Value) 0UL}, new title return page ()))); element;} private static header GeneratePageHeaderPart (string HeaderText) {var element = new header (new paragraph (new ParagraphProperties (new ParagraphStyleId () {val = "header"}), new runs (new text My problem is, I have aligned above both ways to export data with page numbers. If we know that the word document contains 2 pages, then I can add 2 footer. But I do not know how many pages will be created after exporting the data. 


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -