When applying custom style to Excel worksheet cells not everything gets applied in .NET

Hi,

I am currently using Aspose.Cells version 7.1.2.0.

In my code I do the following:

  1. Load xltx file into a workbook (call it tmplWorkbook)
  2. Load html table into another workbook (call it htmlWorkbook)
  3. Copy the cells from the htmlWorkbook into the tmplWorkbook
  4. Loop through the cells in the tmplWorkbook
  5. If the cell contains a date, apply the custom date style located in the tmplWorkbook.Styles
  6. Save the tmplWorkbook into an xls file

After these steps are completed and I open up the excel file and I see that all of my dates have been changed to numbers. After looking at the custom style that I applied I can see that it changed.

The change was that when you right-click the style and click modify, the Number checkbox under "Style includes" is now checked, but it was unchecked when the xltx file was loaded in the tmplWorkbook.

I attached a zip file that duplicates this issue and I included some instructions with some pictures as well to help.

I hope you are able to help me with this issue.

Thanks,

Nathan

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and try this latest version:
Aspose.Cells
for .NET v7.1.2.4

and let us know your feedback.

Also, we have logged this issue in our database. Development team will look into it and once the problem is resolved or we have some update relating to it, we will let you know asap.

This issue has been logged as CELLSNET-40538.

Hi,

After looking into this issue, we found that in your code i.e “cell.SetStyle(tmplWorkbook.Styles[“date”])”, you have used a non-existant style.

It means “tmplWorkbook.Styles[“date”]” does not exist.

So after setting this style, the property of “custom” in style was lost.

Please see the screenshot, please delete the code in red circle, the output would be fine.

Screenshot:

The date style that I am trying to set is a custom style which I created in the excel template (xltx file). Since the style cannot be found, does this mean that custom styles do not get loaded into the workbook?

If they do/can get loaded, can you please show me the right way to do this? Thanks!

Hi,

You need to first create a Style object with your custom style and then you can use it.

Please see the following code.

C#



Style style = workbook.CreateStyle();

//Your custom style format

style.Custom=…


//Set your cell with style

cell.SetStyle(style);

Hello,

This way won't work for me...

Basically, I provide users with an excel template containing custom styles and default styling for each. Using that template, the users can then customize those styles however they see fit as long as they don't change any of the style names. Once they are ready, the users will run my API and pass in the template. I will then load the template in a workbook, look for the style names and apply those styles to the worksheet depending on certain conditions (i.e. the cell has a date).

I need a way to grab each style from the excel template or workbook since I don't know what properties each style will have.

This has actually been working pretty well for me until I found this date issue. It seems like custom fonts and colors get applied without any issue. It's only that number checkbox that won't stay unchecked that is causing an issue.

Thanks,

Nathan

Hi,

Your code is correct, it seems, custom styles are not being loaded.

Please provide me your template that contains your custom style, I will check if it is loaded or not. Also, I will let you know if I find a workaround.

Also, please let me know the steps you used to create a custom style with Ms-Excel.

Hello,

This package is similar to the one I sent before, but with an added file.

In this package, the template.xltx file is the template that contains my custom "date" style.

Also, the docx file called "Creating an Excel Template with a Custom Date Style.docx" explains how I created my template and my custom date style.

Thank you for looking into this and let me know if you need anything else.

Thanks again,

Nathan

Hi,

I have forwarded your issue to development team, it will look into it and once, we will have some update, we will let you know asap.

The comment has been logged against the issue id: CELLSNET-40538

Please see the sample code below for a reference.

C#


for (int i = 0; i < workbook.Styles.Count; i++)

{

st = workbook.Styles[i];


Debug.WriteLine(st.Name);

}



Style st1 = workbook.Styles[“date”];

Hi,

Please download and try the latest fix: Aspose.Cells for .NET

v7.1.2.6.

Please use Cell.SetStyle(workbook.Styles[“date”], true);

This works for me. Thank you very much.

The issues you have found earlier (filed as CELLSNET-40538) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan