Free Support Forum - aspose.com

Addition comment

hello Laurence!

(I received your answer by e-mail. Thank you very much!
Now I repeat my question and add my coode)

I have question about Comment in Aspose.Excel.

I make following functionality:

It is import of data from xls-files to DB. Client prepare files for
import himself. My programm opens a file and reads data "cell by cell", if
expected value in a cell had wrong format or value I add comment to the
cell with text of error. After I propose open the file and to look at "why
the file is not correct for data import"

Problem: for some files (I do not know how the files were created...)
comments are added not correctly.

*** my code***

private void Button2_Click(object sender, System.EventArgs e)

{

Excel excel;

excel = new Excel();

OpenExcel(ref excel, "D:\\Temp\\A.xls"); //test for local computer
Worksheet sheet = excel.Worksheets[0];
Cells cells = sheet.Cells;

Aspose.Excel.Comment comment;
int commentIndex = sheet.Comments.Add(2, 2);
comment = sheet.Comments[commentIndex];
comment.Note = "this is comment";

comment.Height = 2;
comment.Width = 5;

excel.Save("test.xls", FileFormatType.Default, SaveType.OpenInExcel, Response);
}

private static void OpenExcel(ref Excel excel, string falename)

{

excel = new Excel();//(strLicenseFile);

FileStream fs = new FileStream(falename, FileMode.Open, FileAccess.Read);

int fsLength = (int)fs.Length;

byte[] fsData =new byte[fsLength];

fs.Read(fsData, 0, fsLength);

MemoryStream ms = new MemoryStream(fsData);

fs.Close();

excel.Open(ms);

ms.Close();

}


*************
I have got old version Aspose.excel (1.8.6.0). On those files I have
error :

- Excel cannot open the file after an addition of comment (error: file
has errors, data maybe be lost. Then file open without any styles and
comments)

- I downloaded latest Aspose.Excel (3.4.3.0). Now file after addition of
comments is not damaged.

But there are errors:

- I do not see text in comment. Text appears only after set property
Width and Heigth > 5 cm for comment (I open the file in Office XP)

- I do not see comment-box...only arrow (if I try open the file in Office
2003)

My programm code is correct, because it works well for new xls-files that
is created myself in Excel.

How I can use comment so as to it works correctly for !!!any files?

Ludmila.

Hi Ludmila,

About your problems:

- I do not see text in comment. Text appears only after set property
Width and Heigth > 5 cm for comment (I open the file in Office XP)
I fixed it in this attached fix. Please try it.

- I do not see comment-box…only arrow (if I try open the file in Office
2003)
Please verify your Excel file settings. In Tools->Option->View->Comments, please check “Comments and Indicator” option. And please add this line of code:

comment.IsVisible = true;

Hello dear Laurence!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your fast answer.

I have checked up your new dll.

For test small program it is works, Great!

But it works no well in our big project. I have made analysis, and I am going to try to tell you about results.

About small-test project:

------------------------------

It small test project, its code I sent you, I do show file directly.

At first I open xls file in FileStream, after I do

excel.Save("test.xls", SaveType.OpenInExcel, FileFormatType.Default, Response);


About big project:

-----------------------

In big project our application locates in single server.

At first file from user is saved from user local computer on server into temp-folder.
Than I add Comments to the temp-file and save temp-file on server.

excel.Save(_tempFileName, FileFormatType.Default)

Next, I propose to user open the file. (we use modal windows, therefore program code some complication)

Than program-code (for open file for user) similar small-test project.


Analysis works:

-------------------

Previous dll:
------------

In big project I see only arrows after opening of file.

But If I try to open the temp-file by Excel, I see empty region (comment text was empty).


Your new dll:

-------------

In big program I see only arrows about comments (“isVisible” doesn’t help me) after opening of file.

If in the file I select menu “Edit comment” I see sewn region (its height = 0).

If I try to open the temp-file by Excel (the temp-file was created into our big project, it was save in disk) – all Ok! Excel reflects all comment well.

My small-test project reflects comments in temp-file no correctly too. (only arrow)

Please, help me.

Resume:

I see only arrows in my small-test project about comments (I try open temp-file)

I see correct comments if I will open the file by Excel.

Hi Ludmila,

Thanks for your report and analysis.

Could you please check:

1. Have your big program re-built with the new dll?
2. Could you please post your temp file here?
3. You said: “I see only arrows in my small-test project about comments (I try open temp-file)”. What do you mean? How do you open temp file without Excel?

hello Laurence!

I made small application, to explain you "how happen error with comment in file".

private void Button2_Click(object sender, System.EventArgs e)

{

//save file in disk

Excel excel;

excel = new Excel();

OpenExcel(ref excel, "D:\\Temp\\A.xls"); //test for local computer

Worksheet sheet = excel.Worksheets[0];

sheet.ClearComments();

Cells cells = sheet.Cells;

Aspose.Excel.Comment comment;

int commentIndex = sheet.Comments.Add(2, 2);

comment = sheet.Comments[commentIndex];

comment.Note = "this is comment";

excel.Save("D:\\Temp\\A_with_comment.xls", FileFormatType.Default);

}


private static void OpenExcel(ref Excel excel, string falename)

{

excel = new Excel();//(strLicenseFile);

FileStream fs = new FileStream(falename, FileMode.Open, FileAccess.Read);

int fsLength = (int)fs.Length;

byte[] fsData =new byte[fsLength];

fs.Read(fsData, 0, fsLength);

MemoryStream ms = new MemoryStream(fsData); fs.Close();

excel.Open(ms);

ms.Close();

}

private void Button3_Click(object sender, System.EventArgs e)

{

//open file from disk; Please choose "Open" (open Excel)

Excel excel;

excel = new Excel();

OpenExcel(ref excel, "D:\\Temp\\A_with_comment.xls"); //test for local computer

excel.Save("test.xls", FileFormatType.Default, SaveType.OpenInExcel, Response);

}

Explanation:

-----------------

Excel has to be in computer for the test;

1) Press "Button2_" (Button2_Click) - File A.xls + comment will has saved in disk as A_with_comment.xls.

2) Press "Button3" (Button3_Click), You will see offer for "Open, Save, Cancel" of the file (A_with_comment.xls). Please choose "Open". After opening of Excel, look at Sheet1, cell C3 (there is comment), please. You will see only arrow. If you press select menu "edit comment", you will see comment with height = 0

3) Open Explorer and to do double-click on file A_with_comment.xls, please. You will see normal comment.

So, I cannot show comments if I open a file via Aspose that calls Excel. Please help me.


All the best!
Ludmila

Thanks for your sample project. I found the problem and fixed it. Please try this attached version.

dear Laurence,

I checked up your new dll, it works!!! Thank you! :wink:

You helped me very much!

But I had not much time for thorough tests today.

If in next time I will have other problems I will write you.

All the best
Ludmila