Excel border styles in C# are well explored across the internet (here on Stack as much as anywhere) but I've been totally unable to find any documentation covering getting style values; every question, page, and PDF I've found only discusses setting.
How does one get style data from the excel borders in a useful form? (Say, String)
The problem, I'm sure, has something to do with the fact that I'm an absolute C# novice. Dynamic
types confuse and scare me (I miss Java) and this problem may very well center around that. I'm trying to retrieve various styles from ranges in Excel (the ranges may be cells, rows, or entire tables) and translate them into some other form (for demonstration purposes, I've rewritten my code to write HTML styles inline as a String).
using Excel = Microsoft.Office.Interop.Excel;
public static String rangeStyle2InlineHTMLStyle(Excel.Range range)
{
String str = "";
Excel.Style style = range.Style;
Excel.Border border_top = style.Borders[Excel.XlBordersIndex.xlEdgeTop];
Excel.Border border_left = style.Borders[Excel.XlBordersIndex.xlEdgeLeft];
Excel.Border border_right = style.Borders[Excel.XlBordersIndex.xlEdgeRight];
Excel.Border border_bottom = style.Borders[Excel.XlBordersIndex.xlEdgeBottom];
Console.WriteLine(border_top.Color.ToString());
str += "border-top-color:" + color2CSSRGB(border_top.Color) + "; ";
str += "border-left-color:" + color2CSSRGB(border_left.Color) + "; ";
str += "border-right-color:" + color2CSSRGB(border_right.Color) + "; ";
str += "border-bottom-color:" + color2CSSRGB(border_bottom.Color) + "; ";
return "style='" + str + "'";
}
public static String color2CSSRGB(Object c)
{
return "rgb(" + c.R + "," + c.G + "," + c.B + ")";
}
Everything underneath Excel.Style seems to be of dynamic
type, and I have no clue how to use that. MSDN documentation is wonderfully obtuse: There's no clear indication what the members of the Color property are, or what sort of object type I can expect it to return.
I guess this is intentional, that way any one of a number of different color types can be used and even returned, but it's not immediately useful when all I want to know is what's going on in border x... Then again, it's just as likely that this is all entirely the wrong approach.
Thanks