S
Sharad Vyas
Hi,
I am developing an Excel application using VSTO with C#. Application
consists of multiple sheets and very freuquently requires setting the
formalling style for cell programatically. In doing do I have come across
two main issues:
1. If I have any of the sheet protected (even with option selected "To Allow
Formating Cells") within the workbook, the code which sets the cell style
thorws exception suggesting one cannnot do this operation on protected
sheet.
2. So to move on I made sure all the sheets are unprotected. Now I am able
to set the style on Named Range which are made up of one cell. However when
a name range consists of mulitple rows and columns and I want to set the
style of cells in one of the column of this range, it does not see to take
the new style in effect.
Here is my code snipet:
//I first obtain the style string
String strStyle = Globals.ThisWorkbook.GetFormatString(strMsrName);
//set the style of the second column cells of MsrDetails range, which
consists of 10 rows and 2 columns
//This code does not reflect any change in style I am applying here..
for (int k = 1; k <= this.MsrDetails.Rows.Count; k++)
{
Excel.Range cell = ((Excel.Range)this.MsrDetails.Cells[k, 2]);
((Excel.Style)(cell.Style)).NumberFormat = strStyle;
}
//However this works just fine, where ToBe value is a range made up of one
cell only.
((Excel.Style)this.ToBe.Style).NumberFormat = strStyle;
I will really appreciate you input. Thanks so much.
Regards
-Sharad
I am developing an Excel application using VSTO with C#. Application
consists of multiple sheets and very freuquently requires setting the
formalling style for cell programatically. In doing do I have come across
two main issues:
1. If I have any of the sheet protected (even with option selected "To Allow
Formating Cells") within the workbook, the code which sets the cell style
thorws exception suggesting one cannnot do this operation on protected
sheet.
2. So to move on I made sure all the sheets are unprotected. Now I am able
to set the style on Named Range which are made up of one cell. However when
a name range consists of mulitple rows and columns and I want to set the
style of cells in one of the column of this range, it does not see to take
the new style in effect.
Here is my code snipet:
//I first obtain the style string
String strStyle = Globals.ThisWorkbook.GetFormatString(strMsrName);
//set the style of the second column cells of MsrDetails range, which
consists of 10 rows and 2 columns
//This code does not reflect any change in style I am applying here..
for (int k = 1; k <= this.MsrDetails.Rows.Count; k++)
{
Excel.Range cell = ((Excel.Range)this.MsrDetails.Cells[k, 2]);
((Excel.Style)(cell.Style)).NumberFormat = strStyle;
}
//However this works just fine, where ToBe value is a range made up of one
cell only.
((Excel.Style)this.ToBe.Style).NumberFormat = strStyle;
I will really appreciate you input. Thanks so much.
Regards
-Sharad