Free Support Forum - aspose.com

How to get word file formatting

hi,

In my application i am storing the data from richtextbox in which user has the facility to store formatted data into the database. ie. we store

tags with the data. now user can export the report into wordfile(which is in tabular form) .with formatting .
my problem is i am again reading the word file report using aspose and compare the data stored in the database and in the word file. if data is changed application inserts the updated record.but when i pick the data from the word file i am not able to pick the formatting so its considered as modified(which is not actually).eg. when i compare two string faraz and

faraz its condidered as different.
please can you help me . if it is possible to pick the text with formatting.
i am using vb.net (2005)

Sorry, I don't fully understand what you are trying to do. Can you please explain how do you use (or want to use Aspose.Words) and what does it do right or wrong for you.

i am using aspose.words to pick the data saved in ms word table(rows and columns) and store it in sql server database. word data is formatted i.e we have used Bold italics underline in the word file.
how can i save the text with formatting into the database.


this is how i am picking the data.

<span style=“font-size: 10pt; font-family: “Courier New”; color: rgb(43, 145, 175);”>Document<span style=“font-size: 10pt; font-family: “Courier New”;”> doc = new
Document(@“333_101395_faraz\in.doc”);<o:p></o:p>

Table table = doc.FirstSection.Body.Tables[0];

DataTable dt = GetDataTable(table);

///

/// convert word table into Datatable

///

///

/// DataTable

public DataTable GetDataTable(Table table)

{

DataTable dt = new DataTable();

char[] escArr = { '\a' };

foreach (Cell cell in table.FirstRow.Cells)

{

dt.Columns.Add(cell.Range.Text.Trim(escArr));

}

for (int i = 1; i < table.Rows.Count; i++)

{

DataRow row = dt.NewRow();

for (int j = 0; j < table.Rows[i].Cells.Count; j++)

{

row[j] = table.Rows[i].Cells[j].Range.Text.Trim(escArr);

}

dt.Rows.Add(row);

}

return dt;

}



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

Thanks for additional information. I think that you can store your data as html or rtf string. For example see the following code.

public DataTable GetDataTable_107355(Table table)

{

DataTable dt = new DataTable();

char[] escArr = { '\a' };

foreach (Cell cell in table.FirstRow.Cells)

{

dt.Columns.Add(cell.Range.Text.Trim(escArr));

}

for (int i = 1; i < table.Rows.Count; i++)

{

DataRow row = dt.NewRow();

for (int j = 0; j < table.Rows[i].Cells.Count; j++)

{

Document subDoc = new Document();

foreach (Node node in table.Rows[i].Cells[j].ChildNodes)

{

subDoc.FirstSection.Body.AppendChild(subDoc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting));

}

subDoc.FirstSection.Body.FirstParagraph.Remove();

MemoryStream stream = new MemoryStream();

subDoc.Save(stream, SaveFormat.Html);

string html = Encoding.UTF8.GetString(stream.GetBuffer());

int index1 = html.IndexOf("") + 6;

int index2 = html.IndexOf("");

html = html.Substring(index1, index2 - index1);

row[j] = html;

}

dt.Rows.Add(row);

}

return dt;

}

I hope that this will help you.

Best regards.