Aspose.Cells issue

I am using Aspose.Cell

We are creating a excel sheet using aspose.cells and now i have to copy the contents of the sheet into email template (i.e body part) by keeping the same styles n all. Also the body should be editable like we are having bullets sao i want to keep that intact

The challenge is pasted contents in the body part should not have tables of excel

i can paste the contents in the excel that is not the issue. I don’t want the table of excel in the body. just the contents


This message was posted using Email2Forum by Tahir Manzoor.

Hi,

Thanks for your posting and using Aspose.Cells.

Aspose.Cells allows you to create Excel files or manipulate them without the need to install Microsoft Excel. You can read cell values and styles information from Excel files but you cannot copy them into Word document or Email using it. However, you can copy cell contents from one Excel file into another Excel file using Aspose.Cells.

In order to write the cell contents into email, you might need Aspose.Email. You can post your issue in Aspose.Email forum for help in this regard.

If you think, you are facing the issues with Aspose.Cells, then kindly provide us your sample project and source Excel files replicating the issue with the latest version.

Please also download and try the latest version: Aspose.Cells
for .NET v8.1.0.1
and see if it resolves your issue.

Thanks for your quick reply.

Can we convert the contents of worksheet (including the styles) and (excluding the tables) into simple HTML file?

After that i can copy the HTML to the body.


Hi,

Thanks for your posting and using Aspose.Cells.

You can convert your table object into simple cell value data with style using ListObject.ConvertToRange() method.

For example, please see the source xlsx file, it has a simple cell value data and a table object, before converting to html, I have converted the table object into range. Please see the output html object obtained by it in a screenshot for your reference.

I have also attached the output html for you to view.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


worksheet.ListObjects[0].ConvertToRange();


workbook.Save(filePath + “.out2.html”);

I am using Aspose.Cells 7.5.1.0. i Can’t locate the convertToRange method.

I have also attached the excel sheet which i want to convert.

Hi,

Thanks for your posting and using Aspose.Cells.

Are you using Aspose.Cells for .NET or Aspose.Cells for Java?

If you are using Aspose.Cells for Java, then you can find convertToRange() method like the following line.

worksheet.getListObjects().get(0).convertToRange();

Similarly, if you are using Aspose.Cells for .NET, you can find ConvertToRange() method like below

worksheet.ListObjects[0].ConvertToRange()

Further, I have checked your EmailTemplate.xls, it does not have any table (list) objects, so you can simply convert it into html without any issue.

I am using Aspose.cells 7.5.1.0 for .NET. It does not have the method.

The issue is when i copy the sheet into a document as HTML, it copy the cells also with the content. I just want to copy the contents and not the cells/ table.

Did you get my issue?

Can we chat directly?

Sorry. I got the method and tried to implement that. But i m getting the below error

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at Aspose.Cells.Tables.ListObjectCollection.get_Item(Int32 index)
at …

worksheet.ListObjects[0].ConvertToRange();

Please help

Hi,

Thanks for your posting and using Aspose.Cells.

Actually, your EmailTemplate.xls does not contain and table object (or its other name is list object). Therefore, if you try to access list object using worksheet.ListObjects[0] it will throw exception.

We are afraid, live chat is for only simpler queries, for complex queries like yours, we only recommend users to use the forums.

You can explain your requirements with screenshot or output xls/xlsx files. If you just want to read the contents of your email EmailTemplate.xls and not the style information, then you can just read values like the values you get from Cell.StringValue.

If you just want to read contents and convert it to html, you can then first convert your xls file into csv file, since csv format does not support any style, all your style related information will be lost, after that you can convert your csv file into html

Please see the following code. I have attached the output html and screenshot for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\EmailTemplate.xls”;


Workbook workbook = new Workbook(filePath);


//Convert it to csv file

MemoryStream ms = new MemoryStream();

workbook.Save(ms, SaveFormat.CSV);


//Now load csv file again from MemoryStream and convert it to html

ms.Position = 0;

LoadOptions options = new LoadOptions(LoadFormat.CSV);

workbook = new Workbook(ms, options);


workbook.Save(filePath + “.out.html”);

Thanks for your response

My requirement is I want to copy the contents and the style of the emailtemplate worksheet into the email body. Currently my code does that. I use the Microsoft Interop excel to do this.

The issue is if you see below screen shot the sheet is copied as it is with excel table / cells. I do not want the cell/table. i want it as a free text (with style) so that user can edit that. Please confirm, if you got my issue first and then pls suggest me. I know you dont have anything to directly convert it into email template. So if you can convert it into HTML string. I can assign the HTML string to the email body.


Hi,

Thanks for your posting and considering Aspose.Cells.

You can simply convert your workbook into html and then embed it inside your template. Aspose.Cells will give you html file. Once, you will embed it inside the email template, it will not be like a table.

However, Html file or html string will not be editable. If you want to create editable text, then you will have to read your cell values yourself from Excel with Style information then use that information to create editable text with your own method.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\EmailTemplate.xls”;


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.html”);

Thanks for the response. But we are not looking for this solution.

Our aim is to copy the excel sheet into the email body without the cells which i have highlighted above. It should be a free text with the styles.

We are ready to use any Aspose API like Aspose.Word / Email . but we need some solution Please help ?


Hi,

Thanks for your posting and considering Aspose.Cells.

If you want to keep text editable, then you can get the unformatted text by saving your xls file into text format.

Please see the following code, I have attached the output txt file for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\EmailTemplate.xls”;


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.txt”);

You can also use Aspose.Cells to read cell values and their formatting information. You will have to create Email text yourself after reading this information.

For example, the following code reads the cell value of D15 and its Style related information. I have attached the Debug Console Output for your reference.

C#

string filePath = @“F:\Shak-Data-RW\Downloads\EmailTemplate.xls”;


//Create workbook object

Workbook workbook = new Workbook(filePath);


//Access the first worksheet

Worksheet worksheet = workbook.Worksheets[0];


//Read cell D15 value

Cell cell = worksheet.Cells[“D15”];

Debug.WriteLine("D15 Text: " + cell.StringValue);


//Read cell D15 style information

Style style = cell.GetStyle();

Debug.WriteLine("D15 Fill Color: " + style.ForegroundColor);

Debug.WriteLine("D15 Font Color: " + style.Font.Color);

Debug.WriteLine("Is D15 Bold: " + style.Font.IsBold);

Debug.WriteLine("Is D15 Underline: " + style.Font.Underline);


//Besides you can get HTML value of D15

Debug.WriteLine("D15 HTML: " + cell.HtmlString);

Debug Console Output:
D15 Text: Open :
D15 Fill Color: Color [Empty]
D15 Font Color: Color [A=255, R=255, G=0, B=0]
Is D15 Bold: True
Is D15 Underline: Single
D15 HTML: Open :

Hi,

Thanks for considering Aspose.

Besides, you can embed your complete xls/xlsx file in your email body using Aspose.Email. Please see the following article for your reference. Hopefully, it will be helpful for you.