Cells[x-y].Style.Custom Issue


#1

Hi Laurence,
Thank you for the recent updates that have improved the robustness of Range.Copy(). It is quite a big improvement.

The current issue that I am facing now is with Cells[x,y].Style.Custom. I have an Excel template containing 5 worksheets. I explicitly assign custom formats to several cells in order to support multiple currency downloads on our Intranet.

When the Excel template is open, the first worksheet (ordering of the tabs from left to right), is intended to be a static, read only worksheet. I do not populate any data on the worksheet, nor do I set any custom styles.

On the next 3 of the remaining 4 worksheets, I set custom styles for various cells. When I perform the Excel download, the first worksheet, has one of my custom formats applied to it, even though I never reference that worksheet at all in my source code!

Other than that, the custom formatting appears to be working perfectly fine. The approach that I am using to select the cells and apply the styling is:



# region Excel worksheets
private const string ET_REF_SHEET = “Ref”;
private const string ET_SUMMARY_TABLES_SHEET = “Summary Tables”;
private const string ET_DETAIL_TABLES_SHEET = “Detail Tables”;
private const string ET_ADJUSTMENT_GRID_SHEET = “Adjustment Grid”;
#endregion

# region Overall Excel settings
private const byte ET_MAX_SALES_OVERVIEW = 20;
private const byte ET_MAX_SALES_SUMMARY = 6;
#endregion

# region Ref sheet specific row and column locations
private const int ET_REF_START_ROW = 1;
private const byte ET_REF_SALE_NUMBER = 0;
private const byte ET_REF_PROPERTY_NAME = 1;

#endregion

//
// Prepares the download and returns an Excel to the caller
//

protected override Excel RunDownload()
{
// Populate the Ref sheet
Worksheet sheet;
Cells cells;
Cells sumTablesCells;
Cells detailTablesCells;
Cells adjustmentGridCells;
sheet = excel.Worksheets[ET_REF_SHEET];
cells = sheet.Cells;
sumTablesCells = excel.Worksheets[ET_SUMMARY_TABLES_SHEET].Cells;
detailTablesCells = excel.Worksheets[ET_DETAIL_TABLES_SHEET].Cells;
adjustmentGridCells = excel.Worksheets[ET_ADJUSTMENT_GRID_SHEET].Cells;


sumTablesCells[ET_ST_DETAIL_TABLES_START_ROW, ET_ST_DETAIL_TABLES_PRICE_STYLE_COL].Style.Custom = numberStyleStr;

etc.
etc.



Please let me know if this is a known issue, or how you would like to proceed to investigate further.

Thanks
Shan Plourde




#2

Dear Shan,

This is not a known issue. I wrote a simple test case but cannot find the problem.

My test case is:

1. Open a designer file
2. Copy a range from sheet1 to sheet2, sheet3, sheet4
3. Set custom format string to several cells in sheet2, sheet3, sheet4
4. Save the file

I cannot directly run your code. Could you make a simple test case to show your problem? Please send it and your designer file to me.

Thank you.


#3

Thanks Laurence for your reply. I will email you the issue, with the Excel templates and the source code and a brief description of the approach.

Shan Plourde


#4

Hi Shan,

It’s fixed. Please download the latest hotfix and have a try.


#5

Wow, unbelieveable, thanks for the fast turnaround Laurence! I retested both downloads, and the issue is corrected. I had removed my kludges before retesting as well.

Thanks for your dedication!
Shan Plourde