We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extracting Text from Tables with format


what is the best way to extract a document table text content with keeping the formatting of the table, i.e. the final text will have columns and rows type of look.

something like this

Name | Phone Number
First, Last | 800-123-12345
First2, Last2 | 800-456-45678

or if a table can keep the layout that ms word would provide, I know this works somehow when saving a pdf to text using aspose.pdf but I don’t see anyway to do this in aspose. words.

also is there a way to get a fixed max length of the extracted text. i.e. if a string is too long make it break to a new line.


Hi Akram,

Thanks for your inquiry. Could you please share to which file format you want your final output document? Please share your expected output document. We will then provide you more information about your query along with code.

If you want to save the table to text file format, please use TxtSaveOptions.PreserveTableLayout as shown in following code snippet.

Document doc = new Document(MyDir + "in.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
TxtSaveOptions options = new TxtSaveOptions();
options.PreserveTableLayout = true;

Hi Tahir,

I attached three files, the original doc file that I want to export to text, a good sample of output and a bad sample of format.

I generated the bad sample using your suggested code on all tables in the document. you can see that the data is squeezed in some places and the text is getting wrapped to the next line. the good thing about this method is that it’s formatting the text to max line length of 65 which is something good if it can be configured.

Hi Akram,

Thanks for your inquiry.

Please read supported features of plain text (txt) import/export from here:

I have tested the scenario and have found that TxtSaveOptions.PreserveTableLayout property does not work correctly. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10806. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.