xceedsoftware / DocX

Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word.
Other
1.77k stars 473 forks source link

Table Of Content - no indentation #227

Open omribeni opened 6 years ago

omribeni commented 6 years ago

Hi, the table of content does not add proper indentation. Is there a way to change the table of content's format, because when i change it manually to "Simple" rather then "From template" the indentation appears.

Has anybody faced this issue? please let me know.

thanks.

omribeni commented 6 years ago

capture

For some reason using your Table of Content even changes the word picture to not have indentation **the "Format: from Template" may be the problem but there is no way i saw to change it.

please help :)

XceedBoucherS commented 6 years ago

Hi, Thank you for the screenshot.

But, how exactly do you create the Table of Content. You can have a look at our sample in "Samples/TableOfContent/TableOfContentSample.cs". Or you can paste a simple sample showing the issue. Thank you.

Wayne-Mather commented 6 years ago

I have the same issue. Some example code below that has not been tested by myself but based on my Document Generator class.

If you generate and open in Word 2016, you will see that the TOC does not have any indentation.

The current workaround for myself is the following:

  1. Click References on Ribbon
  2. Click Table of Contents
  3. Click "Custom Table of Contents"
  4. Under General, click Formats Drop Down
  5. Change to Formal

Hope this helps anyone else.

Code Snippet Below

using(var doc = Xceed.Words.NET.DocX.Create(fullPathToFileName))
{
     doc.InsertTableOfContents("Table of Contents",
                TableOfContentsSwitches.O // use paragraphs with built in heading styles
                | TableOfContentsSwitches.U // build the toc by using paragraph outline level
                | TableOfContentsSwitches.Z // hide tba leader in web layout
                | TableOfContentsSwitches.H // use hyperlinks
                | TableOfContentsSwitches.W // preserve tabs
                | TableOfContentsSwitches.X // preserve new line characters
                );
            doc.InsertSectionPageBreak();

      var para = doc.InsertParagraph();
      para.Bold();
      para.InsertText("First");
      para.StyleName = "Heading1";

     para = doc.InsertParagraph();
     para.Bold();
     para.InsertText("Second");
     para.StyleName = "Heading2";

     para = doc.InsertParagraph();
     para.Bold();
     para.InsertText("Third");
     para.StyleName = "Heading1";

     para = doc.InsertParagraph();
     para.Bold();
     para.InsertText("Fourth");
     para.StyleName = "Heading2";

     doc.Save();
}
Scantraxx123 commented 5 years ago

Did somebody found an automatic solution? I used @Wayne-Mather method and it worked, but it would be better if I could do it in code.

Wayne-Mather commented 5 years ago

@Scantraxx123 - Judging by the feedback from the new authors and the repository activity, I don't think that they are really active or engage the community for the open source library.

It's a shame because @PrzemyslawKlys created a great library and supported it before it was sold (I pressume) to Xceed.

I have decided to move away from this software when I can but have not found an alternative at this time. My current thoughts are to actually generate LaTex so I can then generate PDF, HTML, RTF.

PrzemyslawKlys commented 5 years ago

@Wayne-Mather Sooner or later this will get fixed. There is a promise that the free version is few versions behind. I assume that if it gets fixed in 1.7 it will get to free version in 1-2 years. Unfortunately, it's business and they have to make money somehow on the pay version. Unfortunately, some features that I really would like to see are supposed to be in pay version only (Core support). It's not an ideal scenario but let's not forget a few years back it's not like people added new features or fixed bugs on a daily basis :-) Anything that requires this commitment has to cost money. I've actually moved into PowerShell and things I do best (system admin stuff). I do have PowerShell module based on DocX called PSWriteWord and I'm using a free version of Xceed just like everyone else. And those that need features ASAP or do it for their business can spend those 530 euro and get the most up to date version there is. The new version should be out in the next few months with the release of 1.6 (pay version). Some new features, possibly some bugs will be fixed with it. We just have to be patient.

Scantraxx123 commented 5 years ago

Sad to hear that, when I first found this libary I really liked it, but now its a little bit frustrating to always here, thats its only available in the pay version. .. I would be very happy if someone found a good replacement for this, could give me the name if it :)

PrzemyslawKlys commented 5 years ago

There is no good replacement and I doubt there will be. It takes a lot of effort to build this one. You have to wait for new features and fixes but at least you get them ;-) For free that is. You know you can still fork it and some people do and work your way on the new version. But I doubt it will get traction since it needs a dedicated team to add new features to it.

Wayne-Mather commented 5 years ago

@PrzemyslawKlys I have no issue with companies needing to survive and having a revenue stream is a mandatory part of that.

The problem I see is that if it looks like they don't really engage with the community around open source parts of their portfolio, how can that convince me to upgrade to get better features and support? With .NET Core 3.0 and the open sourcing of the WPF & Winforms libraries, there maybe renewed interest in these platforms for desktop applications and companies that port their libraries to .NET Standard are going to be in a better position to potentially attract new customers. I say potentially as I don't think being open source will change things, however, if WPF can become Platform Agnostic, that may see it explode in popularity.

I don't mean that the product owner has to implement fixes for the community version instantly, but at least show that they are proactive and care not only about the commercial side but also the community side. Granted I am only a single person but to me it would be in Xceed's best interest to convert anyone using the open source packages into a supported customer.

I totally agree that having a library that works as simple as this is hard to build from the ground up and also think forking the code base would just create more problems than what that would be trying to solve. If I was qualified enough to come up with a fix I would submit it as a PR but I would have to become an expert in the file format and then the code base itself and time is short for this father as it is.

PrzemyslawKlys commented 5 years ago

@Wayne-Mather I agree. They may not seem very supportive here and only occasionally respond to issues (I guess once in 2 months or so, or when a new release is coming soon) but they still do. They just may not have enough resources to run full throttle community support. And since most fixes go to newest, pay version first, there's not much they could do I guess right? Other than asking for what is needed all they can do is update issue and say, fixed in 1.6 as I've seen in other threads. But what does that give you? Not much because it's pay version only and we don't know if it gets added back to free one. And if you really want you can go for the pay version.

1.6 pay version was just released and I see it has support for CORE. It's too bad there was a decision to keep it in pay version only. Hope they change their minds about it. In a few years without CORE on the free version, this product (free version of it) may be dead.

My guess is that this particular issue you're having will get fixed in 1.7 or 1.8. But you will get it in free version in like 2 years. Your best bet, for now, is to either wait for the pay version fix and then buy it or look for another product (there are few on the market). It doesn't seem like anyone wants to build another free product like this.

To summarize, having a community and free product support is hard to maintain for a small company (and I don't think Xceed is huge.

Wayne-Mather commented 5 years ago

Ok, I decided to look at this and have fixed the issue. This is by using the solution mentioned above and refactoring the Styles and Numbering resources to use the one generated by Word 2016.

The link below can download the binary from my branch. If you prefer you can download the entire source code and compile yourself to ensure I have not put any malicious code into it.

XCeed.Words.NET.dll

The steps below outline what I have done:

  1. Removed Resources\default_styles.xml.gz
  2. Generated word doc using nuget version of Xceed.Words.NET.dll
  3. Change the TOC as per my instructions above
  4. Saved the file
  5. Extracted the docx into a directory (it is just a specially formatted zip file)
  6. Copied the word\number.xml and word\styles.xml to the code resources folder
  7. Used Windows Subsystem for Linux to gzip the two file
  8. Ensured the Resources of the solution were correct
  9. Added new static class XceedResources
  10. Modified HelperFunctions. Table and TableOfContents to use new XceedResources static file
  11. Compiled the binary and dropped into the directory of my project that used the nuget version
  12. Ran my program and confirmed word document when opened had indented TOC
XceedBoucherS commented 5 years ago

Hi, You can try with the latest version v1.6 version available for free for 45 days here : https://xceed.com/xceed-words-for-net/. The TOC indentations should already be fixed in that version.

As @PrzemyslawKlys said, Xceed is still maintaining the community edition of this product and will continue to do so. Of course, users of the commercial edition will receive faster support and have more features, but once in a while the users of the community edition also get support. Xceed is happy to get the users feedbacks in order to prioritize the next features/fix to work on.

This product is only one of the products Xceed is working on and they put great effort in it in order to have a powerful tools to help developers around the world work with docx documents. If you do not want to pay for a commercial version, that is no problem, you can always try free trial for 45 days or continue with the community edition, which will continue to be about 2 or 3 versions behind the commercial edition.