I’m currently evaluating your components and have a question about how to best work with formatting merged cells. Currently I have something that looks like:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Worksheet.Cells[iCurrentRow, iCurrentColumn].PutValue(xAxisNode.Attributes["Label"].Value);
if ((iMaxDepth > iDepth) && iCurrentDepth == 1)
{
Worksheet.Cells.Merge(iCurrentRow, iCurrentColumn, 1 + ((iMaxDepth - iDepth - 1) * 2), iLeafNodeCount);
}
else
{
Worksheet.Cells.Merge(iCurrentRow, iCurrentColumn, 1, iLeafNodeCount);
}
//Add formatting here.
The key point to notice here is that the number of columns and rows that will be merge is dynamic and based on contents of the source data. This is boiled down to the variables iMaxDepth, iDepth and iLeafNodeCount in this example. What I want to do is provide formatting to the merged cell. So for example I want the text centered and a medium border. In Excel I would simply right click on the merged cell and set these properties. So I initially thought it would be similar in the component:
Worksheet.Cells[iCurrentRow, iCurrentColumn].Style{etc…}
However, I see that this only formats the first cell in the merged cells. I did a quick search of the forum and found a post saying that you could accomplish formatting of a merge cell like this based on the cell name:
But that only formats the first cell in the merged set. Searching the forum I did see a post saying you could do something like this as:
Worksheet.Cells[“A1”].Style{etc…}
Where “A1” is the first of the merged cells to be formatted. (I think) This has lead me to a number of different questions:
1. Is it better to try and format against the row/column index or the cell name (A1, etc)?
2. Is cell name is preferred, is there an easy way to get this value returned from a cell?
3. Is there a reason that row/column index does not perform the same a cell name?
It may also be that a better implementation should be using something like the .GetMergedRange() method, but it wasn’t clear to me how to apply styles against this. I could just write a few loops and manually execute the code against the range of cells, but it seems there should be a more elegant solution that this.
Thanks for any guidance you can provide.