Hi,
I’ve been trying to find a solution to this problem on your forums but have not found anything conslusive.
When updating an existig document containing a TOC with the following field code
{ TOC \h \z \t “Heading 3;1;Heading 4;2” }
Aspose Words will print No table of contents entries found. in the saved document.
Right-clicking on the the field in Word and selecting Update field will yield a correct TOC. Running it through Aspose Words again will give the initial result.
var document = new Document("test.docx");
document.UpdateFields();
document.Save("test.docx", SaveFormat.Docx);
So I have some additional information here. We use an international version of Word and after inspection of the docx markup we have concluded that this is indeed a bug in your code.
In swedish heading 1 is Rubrik1 and this is reflected in the XML source. that looks like this
My original field code that works in Word but failes in Aspose looks like this { TOC \h \z \t “Rubrik2;1;Rubrik3;2” }
By changing this manually to the following i get the same failure in Word, but now it WORKS in Aspose. { TOC \h \z \t “heading 2;1;heading 3;2” }
Both Rubrik1 and heading 1 are present in the markup, but where as Word uses w:styleId you seem to incorrectly reference w:name w:val causing the TOC to fail rendering properly in both products.
Thanks for your inquiry. Please note that Aspose.Words mimics the behavior of MS Word. If you update the TOC field under English culture by using MS Word, you will get the same output (no table of contents).
In your case, you need to update the TOC field according to your desired culture. Moreover, the list separator in TOC field should be correct. Please note that the list separator is semicolon “;” in Swedish culture. It is comma “,” in English culture. Please use the following line of code to set the culture code for current thread.
Hi,
yes, well this is the answer you’ve provided in numerous other threads and I’ve already tried this with exactly the same result as described above. This is the actual code I use
private byte[] SetProperties(byte[] documentBytes, IDictionary<string, string> properties, SaveFormat saveFormat)
{
using (var documentStream = new MemoryStream(documentBytes))
using (var outputStream = new MemoryStream())
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("sv-SE");
var document = new Document(documentStream);
// We do various proprietary modifactions of the document here
document.UpdateFields();
document.Save(outputStream, saveFormat);
return outputStream.ToArray();
}
}
Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17413. You will be notified via this forum thread once this issue is resolved.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.