Hi
I’m having troubles with tables and their formats when receiving the word document, kept at the database as binary, again.
You can find the original version of the document as attached (original.doc). After getting a saved version of the document from the database, I add another title and convert it to word again. The codes I used for this operation is below and the document after getting a print out is as attached. (Printed.doc)
Document newdoc = new Document();
newdoc.RemoveAllChildren();
Section section = new Section(newdoc);
newdoc.AppendChild(section);
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;
Body body = new Body(newdoc);
section.AppendChild(body);
Paragraph para = new Paragraph(newdoc);
body.AppendChild(para);
Run run = new Run(newdoc);
run.Text = "<1>";
para.AppendChild(run);
binaryContext = dr.Reader["BINARYCONTEXT"] as byte[];
if (binaryContext != null)
{
newdoc.Document.Range.Replace(new System.Text.RegularExpressions.Regex(@"<" + "1" + "\\>"), new ReplaceEvaluatorFindAndHighlight(), false);
currentNode = Rapor.currentNode;
System.IO.MemoryStream ms = new System.IO.MemoryStream(binaryContext);
ms.Position = 0;
Document doc = new Document();
if (binaryContext.Length != 0)
{
doc = new Document(ms);
}
this.InsertDocument(currentNode.ParentNode, doc);
Document docx = new Document();
docx.RemoveAllChildren();
Section section = new Section(docx);
docx.AppendChild(section);
section.PageSetup.SectionStart = SectionStart.Continuous;
section.PageSetup.PaperSize = PaperSize.A4;
Body body = new Body(docx);
section.AppendChild(body);
Paragraph para = new Paragraph(docx);
body.AppendChild(para);
Run run = new Run(docx);
// run.Text = lblBaslik.Text;
run.Font.Bold = true;
para.AppendChild(run);
this.InsertDocument(currentNode.ParentNode, docx);
ms.Close();
}
public class ReplaceEvaluatorFindAndHighlight : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
Rapor.currentNode = e.MatchNode;
return ReplaceAction.Skip;
}
}
As you can see from the screenshot as atteched “BeforeAndAfter.png”, the text on the table is shown beside the table after getting a print-out.
And the title and the table that are supposed to appear on page 3 are shown separately on different pages.
I need your urgent help on the issue.