Free Support Forum - aspose.com

Right side border missing issue for table report

Hi

I have posted the Right border issue for table report already. But

When I add the following code, the right border problem is solved.

Document mainDoc = new Document("C:\\ReportRepository\\ReportTemplate.docx");

DocumentBuilder builder = new DocumentBuilder(mainDoc);

builder.MoveToBookmark("SummaryOfIncidentsClosed");

int index = 0;

index = mainDoc.Sections.IndexOf(builder.CurrentSection);

Aspose.Words.Tables.Table tab;

tab = mainDoc.Sections[index].Body.Tables[0];

tab.Rows[1].RowFormat.Bidi = true;//After this setting the borders are coming fine.

But,

builder.RowFormat.AllowAutoFit = false;// this setting I am doing to ensure that the table looks exactly like reports

1. tab.Rows[1].RowFormat.ClearCellPadding();// this setting makes the borders visible in PDF

2. tab.Rows[1].RowFormat.Bidi = true;// this setting makes borders visible in word document but causing some cells to wrap content

I want to keep the table cells exatcly looks like in report as well as borders should be visble both in word document.

But is is causing some of the cells to wrap their content. For example some cells which contain date and time wrapped to 3 lines, which makes the report looks bad. Can anyone help me get sort of this to make all the cells fit to their preferred widths as well as the borders should be visible.

P.S. When I have done the steps 1 and 2 as mentioned above, the borders are coming fine as well as the cells are not wrapped in PDF, but in word the cells are wrapped and borders are coming fine. I am using latest vesrion of updated DLL(Aspose.word 9.1.0.0)

Hi

I am using Aspose.word 9.0.0.0. I am first generating individual word documents for SSRS reports using ReportViewer.Render method. After that, I am using Aspose.Word to combine these individual word documents into a single one, by replacing a bookmark in word template with each individual document. The problem I am facing is for table reports, the right side border is missing which is coming fine in individual document. I have attched the individual document and the report for which the righ border is missing. Please reply ASAP. I have also attached the template which I am using to combine individual documents into a single one. I tried the following code to get rid of this problem. The right borders are coming fine in PDF. But in word document, still the right borders are missed.

Document mainDoc = new Document("C:\\ReportRepository\\ReportTemplate.docx");

DocumentBuilder builder = new DocumentBuilder(mainDoc);

builder.MoveToBookmark("SummaryOfIncidentsClosed");

int index = 0;

index = mainDoc.Sections.IndexOf(builder.CurrentSection);

Aspose.Words.Tables.Table tab;

tab = mainDoc.Sections[index].Body.Tables[0];

tab.Rows[1].RowFormat.ClearCellPadding();//After this seting Right borders are coming fine in PDF,

//but not in word

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you also provide me your code, which you are using to combine your documents? I will check the issue and provide you more information.

Best regards.

Aspose.Words.License license = new Aspose.Words.License();

license.SetLicense("Aspose.Words.lic");

Document mainDoc = new Document("C:\\ReportRepository\\ReportTemplate.docx");

MergeDocument(mainDoc, "C:\\SummaryOfIncidentsClosed.doc", "SummaryOfIncidentsClosed", 6);

MergeDocument(mainDoc, "C:\\SummaryOfIncidentsOpen.doc", "SummaryofIncidentsOpen", 6);

MergeDocument(mainDoc, "C:\\SummaryOfIncidentsNotMetSLA.doc", "SummaryOfIncidentsNotMetSLA", 17);

private static void MergeDocument(Document mainDoc, string path, string bookmarkName, int sectionNo)

{

if (File.Exists(path))

{

//Get document form specified path.

Document subDoc = new Document(path);

DocumentBuilder builder = new DocumentBuilder(subDoc);

builder.RowFormat.AllowAutoFit = false;//This setting is needed

Aspose.Words.Bookmark bookmark = mainDoc.Range.Bookmarks[bookmarkName];

//Insert document below the specified bookmark.

InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc);

builder = new DocumentBuilder(mainDoc);

//builder.MoveToBookmark(bookmarkName);

int index = mainDoc.Sections.IndexOf(builder.CurrentSection);

mainDoc.Sections.RemoveAt(index + 1);

}

else

{

Node node = mainDoc.Range.Bookmarks[bookmarkName].BookmarkStart;

while (node.NodeType != NodeType.Section) node = node.ParentNode;

node.Remove();

}

}

private static void InsertDocument(Node insertAfterNode, Document srcDoc)

{

// Make sure that the node is either a pargraph or table.

if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &

(!insertAfterNode.NodeType.Equals(NodeType.Table)))

throw new ArgumentException("The destination node should be either a paragraph or table.");

//Inserting into the parent of the destination paragraph.

CompositeNode dstStory = insertAfterNode.ParentNode;

// This object will be translating styles and lists during the import.

NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting);

// Loop through all sections in the source document.

foreach (Aspose.Words.Section srcSection in srcDoc.Sections)

{

// Loop through all block level nodes (paragraphs and tables) in the body of the section.

foreach (Node srcNode in srcSection.Body)

{

// Let's skip the node if it is a last empty paragarph in a section.

if (srcNode.NodeType.Equals(NodeType.Paragraph))

{

Aspose.Words.Paragraph para = (Aspose.Words.Paragraph)srcNode;

if (para.IsEndOfSection && !para.HasChildNodes)

continue;

}

//This creates a clone of the node, suitable for insertion into the destination document.

Node newNode = importer.ImportNode(srcNode, true);

//Insert new node after the reference node.

dstStory.InsertAfter(newNode, insertAfterNode);

insertAfterNode = newNode;

}

}

}

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. If you remove the highlighted line from your code, right border is displayed properly in output Word document. But in this case it is lost upon converting to PDF:

private static void MergeDocument(Document mainDoc, string path, string bookmarkName, int sectionNo)

{

if (File.Exists(path))

{

//Get document form specified path.

Document subDoc = new Document(path);

DocumentBuilder builder = new DocumentBuilder(subDoc);

builder.RowFormat.AllowAutoFit = false;//This setting is needed

Aspose.Words.Bookmark bookmark = mainDoc.Range.Bookmarks[bookmarkName];

//Insert document below the specified bookmark.

InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc);

builder = new DocumentBuilder(mainDoc);

builder.MoveToBookmark(bookmarkName);

int index = mainDoc.Sections.IndexOf(builder.CurrentSection);

mainDoc.Sections.RemoveAt(index + 1);

}

else

{

Node node = mainDoc.Range.Bookmarks[bookmarkName].BookmarkStart;

while (node.NodeType != NodeType.Section) node = node.ParentNode;

node.Remove();

}

}

Maybe you should keep the original section. You can use Document.AppendDocument method to concatenate documents. In this case section settings are preserved after concatenating documents.

Best regards.

Hi

tab.Rows[1].RowFormat.RightPadding = 12.0;

By inserting the above code, my problem gets solved.

Regards

Mahendra

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. It is perfect that you managed to resolve the problem.

Best regards.