novacode-docx

Set docx properties using library .docx

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-19 15:48:21
问题 How to set properties like title, author, subject for a file created with docx library for .net ? docx 回答1: The DocX project that you provided appears to be able to easily access the metadata properties that you are referring to and can do so quite easily by using the CoreProperties property as seen below : // Load your Document var wordFile = Novacode.DocX.Load(@"your-docx-file-path"); // Access Metadata properties var props = wordFile.CoreProperties; The issue here is that this collection

How can I remove all extraneous spaces from a *.docx file?

妖精的绣舞 提交于 2019-12-25 07:46:26
问题 I want to remove all superfluous spaces from a .docx file. If there are cases where there are more than two, to accomplish this manually I need to do a search-and-replace for two spaces multiple times to get all of them, and it's hard to tell when I'm "finished." 回答1: This code, using the docx library, accomplishes it: private void RemoveSuperfluousSpaces(string filename) { bool superfluousSpacesFound = true; using (DocX document = DocX.Load(filename)) { List<int> multipleSpacesLocs; while

C# DocX: Inserting new numbered list continues numbering

倾然丶 夕夏残阳落幕 提交于 2019-12-23 19:08:12
问题 I am trying to insert several numbered lists into a Word document using Novacode DocX. Something like this: var doc = DocX.Create("somedoc.docx"); var list = doc.AddList(listType: ListItemType.Numbered, startNumber: 1); doc.AddListItem(list, "Number 1", 0, listType); doc.AddListItem(list, "Number 2", 0, listType); doc.InsertList(list); doc.InsertParagraph(); //just to get some space between. var secondList= doc.AddList(listType: ListItemType.Numbered, startNumber: 1); doc.AddListItem

How can I control table column width in Word documents using DocX?

十年热恋 提交于 2019-12-12 13:53:12
问题 I am trying to recreate a table like this: I am using the DocX library to manipulate Word files, but I'm having trouble getting the widths right. Trying to set the widths of cells only seems to work when it's not set to the window autofit mode, and it only seems to resize when the specified width is greater than half of the table width, or rather, I can make a cell bigger than half the width but not smaller. What would be the simplest way to reproduce the intended table? 回答1: I found the

Novacode Determine If Word Style Is A Table

心不动则不痛 提交于 2019-12-11 00:13:25
问题 I need to parse several .docx files and find using Novacode DocX is making this a much easier task. The way I need to parse these documents is from a top-down approach where when I come across a certain "object" ( word table, picture, graphic, equation, ... ) do something specific. I wrote the following code. Given a document this code will navigate through all the paragraph instances in-order and print out the styles. I noticed that some of these styles ( "Normal" in this case ) are actually

c# Find and Replace Text in a Word Document

烂漫一生 提交于 2019-12-10 12:23:12
问题 i want to Create and Manipulate Word Documents Programmatically Using DocX ! and create a word template InvoiceTemplate.docx this is my code : protected void CreateDoc_Click(object sender, EventArgs e) { //Createa docx File DocX gDocument; gDocument = DocX.Load(@Server.MapPath("InvoiceTemplate.docx")); gDocument = CreateInvoiceFromTemplate(DocX.Load(@Server.MapPath("InvoiceTemplate.docx"))); gDocument.SaveAs(@Server.MapPath("~/DocX/NewLoadedShipment.docx")); } private static DocX

Nested Bulleted lists in Novacode docx

落花浮王杯 提交于 2019-12-08 09:23:28
问题 How can i create nested bulleted/Ordered lists with Novacode for docx? I've done some research but couldn't find anything, any help is appreciated. 回答1: Hope it's not too late, I've just figured it out a couple hours ago class Program { static void Main(string[] args) { string docPath = "PATH TO YOUR OUTPUT WORD DOCUMENT" ; var doc = DocX.Create(docPath); var l = doc.AddList("Item #1", 0, ListItemType.Bulleted, 0); doc.AddListItem(l, "Item #2"); doc.InsertList(l); doc.Save(); } } 回答2: You

Looping Through Each Word In Word Document Using Docx Library

筅森魡賤 提交于 2019-12-08 04:03:45
问题 I am trying to make a small program to apply autocorrect changes to an exiting document. I am using the docX library. My question is, how do you iterate (or loop) through each word in the document, using the docX library, to check if it needs to be corrected or not (I have already inserted all auto correct entries in a list<T> ). 回答1: try this... DocX document = DocX.Load( <document path> ); foreach(Novacode.Paragraph item in document.Paragraphs) { // use this if you need whole text of a

Novacode DocX Different page orientations within the same document

半世苍凉 提交于 2019-12-07 06:52:04
问题 Using the following code, I'm trying to create a document in which pages 2 and 3 are landscape while the others are portrait. All should be 8.5" x 11". using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { using (DocX document = DocX.Create(ms)) { document.PageLayout.Orientation = Novacode.Orientation.Portrait; document.PageWidth = 816F; document.PageHeight = 1056F; document.MarginTop = 50F; document.MarginRight = 50F; document.MarginBottom = 75F; document.MarginLeft = 50F;

Looping Through Each Word In Word Document Using Docx Library

孤街浪徒 提交于 2019-12-06 16:49:58
I am trying to make a small program to apply autocorrect changes to an exiting document. I am using the docX library. My question is, how do you iterate (or loop) through each word in the document, using the docX library, to check if it needs to be corrected or not (I have already inserted all auto correct entries in a list<T> ). try this... DocX document = DocX.Load( <document path> ); foreach(Novacode.Paragraph item in document.Paragraphs) { // use this if you need whole text of a paragraph string paraText = item.Text; // use this if you need word by word foreach(var data in item.MagicText)