xceedsoftware / docx Goto Github PK
View Code? Open in Web Editor NEWFast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word.
License: Other
Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word.
License: Other
Hi Team,
Below mentioned text will be present in our TEST.docx file.
sample example paragraph:
To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other.
For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
We want Implement following requirements using DocX API
Regards,
Arun
Looks like there is no support for the Chinese character set:
public Paragraph Font(FontFamily fontFamily)
{
ApplyTextFormattingProperty
(
XName.Get("rFonts", DocX.w.NamespaceName),
string.Empty,
new[]
{
new XAttribute(XName.Get("ascii", DocX.w.NamespaceName), fontFamily.Name),
new XAttribute(XName.Get("hAnsi", DocX.w.NamespaceName), fontFamily.Name), // Added by Maurits Elbers to support non-standard characters. See http://docx.codeplex.com/Thread/View.aspx?ThreadId=70097&ANCHOR#Post453865
new XAttribute(XName.Get("cs", DocX.w.NamespaceName), fontFamily.Name), // Added by Maurits Elbers to support non-standard characters. See http://docx.codeplex.com/Thread/View.aspx?ThreadId=70097&ANCHOR#Post453865
}
);
return this;
}
Adding support should be as simple as:
new XAttribute(XName.Get("eastAsia", DocX.w.NamespaceName), fontFamily.Name)
If one adds a multi-line string using Paragraph.Append, AppendLine, InsertText, ReplaceText, ..., for each new line in actually two new lines are added to the document.
The reason is how strings a formatted in HelperFunctions.FormatInput. Enviroment.NewLine (on Windows) corresponds to '\r\n'. Before 1.0.0.20 only '\n' was considered as a special character adding a new line. However, in 24dd8ee also '\r' was given a special character treatment to issue a new line. Thus a standard Environment.NewLine = '\r\n' now causes two line breaks to be added to the document.
A workaround is to use Replace("\r\n", "\n") on a given string before passing it to Append, AppendLine, InsertText, ReplaceText, ... of a Paragraph, however this appears a little awkward.
I have tested method for same.
/// <summary> /// Set Table column width by prescribing percent /// </summary> /// <param name="widthsPercentage">column width % list</param> /// <param name="totalWidth">Total table width. Will be calculated if null sent.</param> public void SetWidthsPercentage(float[] widthsPercentage, float? totalWidth) { if (totalWidth == null) totalWidth = this.Document.PageWidth - this.Document.MarginLeft - this.Document.MarginRight; // calculate total table width List<float> widths = new List<float>(widthsPercentage.Length); // empty list, will hold actual width widthsPercentage.ToList().ForEach(pWidth => { widths.Add(pWidth * totalWidth.Value / 100); }); // convert percentage to actual width for all values in array SetWidths(widths.ToArray()); // set actual column width }
Can be added to Table class
Hello,
I'd like to replace a placeholder with some text contaning pure text and URLs.
Is there a way to replace the url viewed as pure text as an url?
bye
Is there's a support for .net core?
My Solution runs on Unix
Hi,
How to create a list like a invoice with products?
I need like this sample http://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/How-to-Use-Mail-Merge-to-Create-Report.html
thanks
When there are bookmarks at header or footer,I use document.Bookmarks["bookmk"].SetText("ABC") to set text at bookmark "bookmk",then NullReferenceException occured.And the Bookmarks Collection doesn't contains bookmarks at header and footer,just contains bookmarks at main content.
Hello,
I could not find the license information for this project on GitHub. However, Codeplex states that it's Ms-PL (https://docx.codeplex.com/license). Is this information current and correct? Could you please include it on project's README.md? (I can create a pull request for that).
Thanks
On line 641 of internal static bool IsSameFile(Stream streamOne, Stream streamTwo)
if (streamOne.Length != streamOne.Length)
{
// Return false to indicate files are different
return false;
}
Is there any reason to check if the length of the same stream does not match? Should not one of those be streamTwo?
Documentation for this project is spread through many old blog posts in Cathals Corner.
Wouldn't it be better to start centralizing documentation here in the wiki?
The FontSize() method in Paragraph.cs does not allow for half sizes, and an exception is thrown erroneously. I believe this is because of the if logic in line 2969 if (fontSize - (int)fontSize == 0).
This should be a quick fix and I'll submit a pull request shortly. Adding to issues list for documentation.
What's the difference ???
This code should be added to the Parse function in Formatting.cs
case "vertAlign":
var script = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName), null);
formatting.Script = (Script)Enum.Parse(typeof(Script), script);
break;
I'd like to let the headings get numbered automatically. (Just like at Word 2010 when you press the button "List with many levels" and select the option where the headings get numbered just as I want them to (the standard word functionality)). Is there a way to accomplish this using DocX
I want to find FormFields, Comments, I look at the code is not found a way to find these objects
doc.Copy(): create a new DocX object from an existing one.
Can be done pretty easily by copying the underlying document content via memory stream.
Something like this:
DocX doc;
var stream= new MemoryStream();
/* some code to populate the document */
doc.SaveAs(stream);
stream.Seek(0, SeekOrigin.Begin);
DocX doc2= DocX.Load(stream);
With DocX, is there an easy way to loop through all the words in a Document and alter them if necessary. Here is the interop equivalent code, but it requires Office and very slow:
var words = App.ActiveDocument.Words;
for (int i = 1; i <= words.Count; i++)
{
var word = words[i];
var text = word.Text;
if (text.Equals("\r"))
{
continue;
}
//This method is some kind of spellchecker. Returnes the fixed version of a word.
var deas = Deasciifier.Deasciify(text);
if (deas.Equals(text))
{
continue;
}
word.Select();
App.Selection.TypeText(deas);
}
I've added a collection for Content Controls and a couple of methods for replacing text in the, It's on my fork, but I'm very new to GitHub and I'm unsure what to do from here. Help, please?
While using DocX in a plugin for CRM Online, I came across an error because I don't have privilege to get the current user. This shouldn't be an issue if track changes is off (and isn't an issue for Paragraph.InsertText as it checks trackChanges before calling Paragraph.CreateEdit). I'm thinking this may be a bug (not quite bug, but unnecessary), and that Paragraph.RemoveText should be similar to Paragraph.InsertText for calling CreateEdit. Avoiding this call should also avoid the call to get current user.
Paragraph.RemoveText lines of code: 3710 and 3748
Paragraph.InsertText lines of code: 2099 and 2119
I am trying to run DocX with Mono under debian 7. I'm using the git build, Building with xbuild is successful and the Hello world example succeed.
But the document can not open.
Run Examples.exe can create docx files, but can't open too.
some docx fails with:
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Novacode.DocX.PopulateDocument (Novacode.DocX document, System.IO.Packaging.Package package) <0xb44bd2e8 + 0x007c7> in :0
at Novacode.DocX.PostLoad (System.IO.Packaging.Package& package) <0xb44cf650 + 0x00267> in :0
at Novacode.DocX.Load (System.String filename) <0xb38f4558 + 0x0018f> in :0
at Examples.Program.CreateInvoice () <0xb36f3bd0 + 0x00033> in :0
at Examples.Program.CreateInvoice () <0xb36f3bd0 + 0x000d7> in :0
at Examples.Program.Main (System.String[] args) <0xb743ced0 + 0x000d3> in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at Novacode.DocX.PopulateDocument (Novacode.DocX document, System.IO.Packaging.Package package) <0xb44bd2e8 + 0x007c7> in :0
at Novacode.DocX.PostLoad (System.IO.Packaging.Package& package) <0xb44cf650 + 0x00267> in :0
at Novacode.DocX.Load (System.String filename) <0xb38f4558 + 0x0018f> in :0
at Examples.Program.CreateInvoice () <0xb36f3bd0 + 0x00033> in :0
at Examples.Program.CreateInvoice () <0xb36f3bd0 + 0x000d7> in :0
at Examples.Program.Main (System.String[] args) <0xb743ced0 + 0x000d3> in :0
fuchsia@debian:~/docx_test/Examples/bin/Release$ '''
I am using DocX and it is a great library, very powerful. I generate dynamic docs with it and worked great.
Now I have a block of html and I want to add that in an existing doc, while keeping all the formatting, like b /br font size h1 etc, I want to know how can I do that with DocX or I need to use some other library.
Thanks
Hi
I need ability to replace images in whole document, but I found that you forgot to add Images property into footer. You have it in header and main body, but not footer. Footer only has Pictures, but in "Picture" class you hided actual "Image" object and users cannot replace content,
I think the best way will be to make Image in Picture class as a public property.
On using BarChart() function from example and just changing cart groping to 'Stacked'
// Create chart. BarChart c = new BarChart(); c.BarDirection = BarDirection.Column; c.BarGrouping = BarGrouping.Stacked; c.GapWidth = 400; c.AddLegend(ChartLegendPosition.Bottom, false);
The multiple series are not set in same line.
Am I missing something?
how to set Image Layout ?
If have little knowledge of the ooxml specs, and don't understand why there is a difference between the propertie Sections of a document and the GetSections() method.
Sections returns 1 section less than GetSections()
I think it is the last section of the document missing
Is this supposed to work this way?
And if so: why?
It looks like after creating a docx file, memory is not being released.
This is how we use DocX:
using (_doc = DocX.Create(_fileName))
{
_doc.AddFooters();
_doc.PageLayout.Orientation = Novacode.Orientation.Landscape;
_doc.AddProtection(EditRestrictions.readOnly);
...
...
_doc.Footers.even.PageNumbers = true;
_doc.Footers.odd.PageNumbers = true;
_doc.Save();
}
Not sure if I am missing something, but when I call DocX.ApplyTemplate("template.dotx", true) everything in a document gets replaced with the content from the template, regardless of whether I set includeContent to true or false. Isn;t it supposed to apply stles only, and if content is to be included, it should be appended, not replace existing content?
How can i add a table of contents at the beggining of the document? Everytime i run it it gets added to the end
var p = this.wordDocument.InsertParagraph();
var ToC = this.wordDocument.InsertTableOfContents(this.Title, this.TableSwitch,);
var paragraphT = this.wordDocument.Paragraphs[0].InsertParagraphBeforeSelf(p);
On import of .doc/.docx text alignment of entire document is changed to Justified.
It would be useful to hand over the Replace to accept a delegate that can do work against regex matches, for example in a mailmerge scenario.
Unfortunately, DocX currently doesn't read out the "app.xml" file that does exist for a lot of *.docx files in the "/docProps" subfolder (side-by-side with "core.xml", which is being read out).
I would really love to have access to the information like count of words, count of characters etc. that is stored in the "app.xml" - it seems to me, it would be almost the same code as for the "CoreProperties" property on the "DocX" object. Can't be that hard to do! :-) Any hope that'll show up soon?
here is my code
Image img = doc.AddImage(@".\images\test.jpg");
Picture pic = img.CreatePicture();
pic.Height = 100;
pic.Width = 200;
Paragraph p = doc.InsertParagraph("", false);
pic.SetPictureShape(RectangleShapes.rect);
p.InsertPicture(pic);
doc.SaveAs($"{path}\\src\\newDoc.docx");
when executed the document is saved and the image is placed on the bottom but it is a blank image.
While it is possible to get a list of the footnotes, I am not able to add, remove or edit footnotes.
Any plans on adding that?
is there a way to append to a paragraph with custom formating like with the formatting class,
example:
p.Append('string', formatting)
This function calculates the column widths in points and assigns the results to Cell.Width. However Cell.Width uses pixels not points. Need to multiply by 96 and divide by 72 before calling Table.SetWidths inside this this function.
Note - I am using the 1.0.0.22 tag and manually added Table.SetWidthsPercentage, so maybe this is not an issue in master branch.
Just like bookmark.tables in COM.
I live in Belgium, and our decimal sign is a komma
The setter for IndentationBefore and IndentationAfter makes a invalid xml string (Word 2016 has a problem reading this, LibreOffice 5 does read it correct)
This is the xml generated:
<w:ind w:left="706,800005435944" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />
Solution:
Change line 785 and 728 from this:
string indentation = ((indentationBefore / 0.1) * 57).ToString();
to this:
string indentation = ((indentationBefore / 0.1) * 57).ToString(CultureInfo.GetCultureInfo("en-GB"));
In the AddCustomProperty method, there is the following code to handle the situation where a custom property with the same name already exists:
if (customProperty != null)
customProperty.Remove();
This does not appear to achieve the desired results. It does seem to replace the Custom Property, but when you then save the DocX object to a file, the custom.xml package does not exist.
DocX is not supported in asp.net core 1.0
How to apply text formatting in list ?
I have tried to follow the example below for the custom properties. However, I have to update the fields manually on the generated document ..
http://cathalscorner.blogspot.com.eg/2009/02/docx-net-library-for-manipulating-word.html
The following code generates a document in which the strings are reversed...
using the latest NuGet - version DocX.1.0.0.19
public static void DocumentHeading()
{
Console.WriteLine("\tDocumentHeading()");
using (DocX document = DocX.Create(@"C:\TEMP\DocumentHeading.docx"))
{
foreach (HeadingType heading in (HeadingType[])Enum.GetValues(typeof(HeadingType)))
{
string text = string.Format("{0} - The quick brown fox jumps over the lazy dog", heading.EnumDescription());
Paragraph p = document.InsertParagraph();
p.AppendLine(text).Heading(heading);
}
document.Save();
Console.WriteLine("\tCreated: docs\\DocumentHeading.docx\n");
}
}
I wish to add a page break in my document, and to achieve that I'm using the "InsertSectionPageBreak" method.
That actually breaks the flow to the next page, but the size of the page layout of the new page isn't the same as the first one. In other words, the very first page is an A4-size layout, and if I do NOT add page breaks, any further page will follow that size. If I add a page break on the first page, the 2nd and the 3rd are Letter-sized, whereas the 4th is an A4 back.
Tested with the NuGet release 1.0.0.19.
Any clue?
Very nice job, BTW!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.