If condition1 is not True, entire section 5 will be removed
if condition1 is True and condition2 is also True, then 5.1.1 to 5.1.4 will be displayed
if condition1 is True and condition2 is NOT True, then 5.1.2 and 5.1.3 will be removed; and because its removing 5.1.2 and 5.1.3, as a standard word behaviour, the original 5.1.4 will be reflected as 5.1.2 ensuring that the numbering is still correct.
This is quite an interesting way of doing, as it ensures that rules can be easily set, and the docx template is something which a normal end user can managed (with some basic level of training). Wonder can aspose achieve something like this? Or how will Aspose achieve this requirement need?
As we are currently moving out of the legacy solution, i am looking for a third party plug-in which can achieve the same. hope to get some good news from you.
Looking at the reference link, couple of questions to clarify as I am trying to maniupulate a docx template,
the earlier link you provided on “find and replace” is under the section “Programming with documents” which i presume can be used to manipulate docx template. please confirm
the second link provided “using conditional blocks” is under “LINQ Reporting Engine”. Can this conditional block be also used on a docx template? or its only used for reporting purposes?
if there is any sample codes or links to how others used this conditional blocks in documents, appreciate if you can share them over. cheers!!
You can use both find/replace and LINQ Reporting Engine with any of them. After loading the document there is no difference what was the input, the document is already loaded into the Aspose.Words DOM and you can manipulate it as it is required.
Here is simple code that demonstrates how to use conditional blocks:
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.RemoveEmptyParagraphs;
// A simple variable is used as data source, but you can use JSON, XML or complex objects as datasource
engine.BuildReport(doc, true, "test");
doc.Save(@"C:\Temp\out.docx");
Is there any specific documentation which can guide me on how to get started with Aspose? (i.e. how to consume the API?). I believe there is a trial version of 30 days or so.
If eventually i want to use aspose, can this be installed on a server of my choice? due to sensitivity of my project.
Sure, you can learn how to get started with Aspose.Words in our documentation: https://docs.aspose.com/words/net/installation/
Aspose.Words is a class library and you can install it from NuGet and use as any other .NET class library. In evaluation mode Aspose.Words has only two limitations: it limits the maximum size of the processed document to several hundred of paragraphs and injects an evaluation watermark into the document. If you would like to test Aspose.Words without evaluation version limitations, you can request a free 30-days temporary license . Please see our documentation to learn more about licensing: https://docs.aspose.com/words/net/licensing/
Sure, as it was mentioned above, Aspose.Words is a stand alone .NET library, so you can use it on the server of your choice as any other .NET library.
By installing the " Aspose.Words for .NET", does it include the “LINQ Reporting Engine” capability? or i need to install it separately? if yes, kindly guide how to get it installed?
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.RemoveEmptyParagraphs;
// A simple variable is used as data source, but you can use JSON, XML or complex objects as datasource
engine.BuildReport(doc, true, "test");
doc.Save(@"C:\Temp\out.docx");
@KeithOon You can use stream to read bytes and save it to bytes:
Document doc;
using (MemoryStream inputStream = new MemoryStream(bytes))
doc = new Document(inputStream);
using (MemoryStream outputStream = new MemoryStream())
{
doc.Save(outputStream, SaveFormat.Docx);
var outputBytes = outputStream.ToArray();
}
thanks Vyacheslav and Alexey, you both have being very helpful. Slowly but surely, i will get there.
understand for buildreport, i can pass in a json, is there any examples on this? or where can i find these examples on the aspose documentation myself? currently, struggling abit on this as i am trying to pass in multiple conditions, so that i can build many if else and nested if else if possible in docx template.
// A simple variable is used as data source, but you can use JSON, XML or complex objects as datasource
engine.BuildReport(doc, true, "test");
Using below, i was able to achieve what i need of conditionally removing paragraphs or sections. Is it possible to achieve the same without having to conditionally declare a class structure in C#? will be good as if we are able to do so. In event if the template changes. the C# code is dynamic enough to handle it. I was trying to look at json as a source to see any examples of it but was unsuccessful. Can you provide some guidance?
using System;
using System.Collections; // Add this using directive for IEnumerator
using Aspose.Words;
using Aspose.Words.Reporting;
namespace ReportGeneratorApp
{
public class ConditionalData : IEnumerable
{
public string TestA { get; set; }
public string TestB { get; set; }
// Implement IEnumerable explicitly
public IEnumerator GetEnumerator()
{
yield return this;
}
}
class Program
{
static void Main(string[] args)
{
// Load the document
Document doc = new Document(@"C:\input.docx");
// Create an instance of your data source
var conditionalData = new ConditionalData
{
TestA = "CorrectApproach",
TestB = "Yes"
};
// Initialize the reporting engine
ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.RemoveEmptyParagraphs;
// Build the report using the document and conditional data
engine.BuildReport(doc, conditionalData, "");
// Save the output document with a specific name
doc.Save(@"C:\output.docx");
Console.WriteLine("Report generation completed.");
}
}
}
// Initialize the JsonDataSource with the JSON string
JsonDataSource jsonDataSource = new JsonDataSource(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(ssJsonString)));
// Build the report using the document and JSON data
engine.BuildReport(docx, jsonDataSource, "jsonData");
its me a again. now i have another need from business.
is there a plugin that can be installed in OFFICE WORD from Aspose?
check out this youtube on this platform “Neota Logic” which was previously used by business. (3:14min onwards for demo) AL TV Product Walk Through - Neota Logic - Doc Automation (youtube.com)
With a plug-in installed in WORD, anyone is able to create “variables” or “conditions” in DOCX template via GUI and then subsequently import the word template in the platform
The experience liked by business is that this significantly reduce mistake due to typos, etc.
Does Aspose has any extended feature to install plugin in WORD?
If no, is there any possibility of achieving this kind of capability using the various methods/functions available in Aspose?
Also, we have a task WORDSNET-25915 to investigate possibility of using Aspose.Words for creating Word add-in using Office JavaScript (Office.js). We will keep you updated and let you know once analysis is done.