Hi,
I’m trying to move content outside the table, when I try to do that I’m loosing style of subscripted content is there a way to retain entire line as ease without changing styles?
Hi,
I’m trying to move content outside the table, when I try to do that I’m loosing style of subscripted content is there a way to retain entire line as ease without changing styles?
Please note that Aspose.Words mimics the behavior of MS Word. If you move the content from table using MS Word, you will get the same output.
Could you please attach the following resources here for further testing?
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.
Hi,
Please refer the code used.
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Fields;
using Aspose.Words.Lists;
using Aspose.Words.Replacing;
using Aspose.Words.Tables;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using Paragraph = Aspose.Words.Paragraph;
using Table = Aspose.Words.Tables.Table;
namespace AsposeLibraryWord
{
class Program
{
static void Main(string[] args)
{
string fileName = @"D:/PWS/Automation/inputdoc.docx";
Aspose.Words.Document doc = new Aspose.Words.Document(fileName);
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Table t in doc.GetChildNodes(NodeType.Table, true))
{
string rowText = t.Rows[0].ToString(SaveFormat.Text).Trim();
var match = Regex.Match(rowText, @"^(Table\s(\d+))");
if (match.Success)
{
if (t.PreviousSibling == null)
{
t.ParentNode.InsertBefore(new Paragraph(doc), t);
builder.MoveTo(t.PreviousSibling);
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertField(@"SEQ Table \* ARABIC", "");
builder.Write(rowText);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Caption;
t.Rows[0].Remove();
}
else
{
t.ParentNode.InsertBefore(new Paragraph(doc), t);
builder.MoveTo(t.PreviousSibling);
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertField(@"SEQ Table \* ARABIC", "");
builder.Write(rowText);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Caption;
t.Rows[0].Remove();
}
}
}
string dataDir = @"D:/PWS/Automation/ConvertedDOC.docx";
doc.Save(dataDir);
}
}
}
You can use Document.StartTrackRevisions method as shown below to achieve your requirement. Moreover, we suggest you please read the following article.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "inputdoc.docx");
doc.StartTrackRevisions("aw");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Table t in doc.GetChildNodes(NodeType.Table, true))
{
string rowText = t.Rows[0].ToString(SaveFormat.Text).Trim();
var match = Regex.Match(rowText, @"^(Table\s(\d+))");
if (match.Success)
{
if (t.PreviousSibling == null)
{
t.ParentNode.InsertBefore(new Paragraph(doc), t);
builder.MoveTo(t.PreviousSibling);
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertField(@"SEQ Table \* ARABIC", "");
builder.Write(rowText);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Caption;
t.Rows[0].Remove();
}
else
{
t.ParentNode.InsertBefore(new Paragraph(doc), t);
builder.MoveTo(t.PreviousSibling);
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertField(@"SEQ Table \* ARABIC", "");
builder.Write(rowText);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Caption;
t.Rows[0].Remove();
}
}
}
doc.Save(MyDir + "21.9.docx");
Issue is not Track Revisions. But subscripted value are appending back as normal text.
You are inserting the row text as simple text using DocumentBuilder.Write method. So, it is inserted with normal style. You need to clone the nodes of table’s cell and insert them using CompositeNode.InsertAfter method.
Following code example shows how to insert cells paragraphs before table. Hope this helps you.
Paragraph node = (Paragraph)t.ParentNode.InsertBefore(new Paragraph(doc), t);
builder.MoveTo(t.PreviousSibling);
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertField(@"SEQ Table \* ARABIC", "");
foreach (Cell cell in t.Rows[0].Cells)
{
foreach (Paragraph para in cell.Paragraphs)
{
node = (Paragraph)node.ParentNode.InsertAfter(para.Clone(true), node);
}
}
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Caption;
t.Rows[0].Remove();
Hi,
Thank you that worked.