I have a complicated setup, actually using a Tuple to pull in
disparate items, like cell behavior overrides, property maps
(reflection PropertyInfo references) to the cell contents and
PropertyInfo references to color (integer converted to bytes) for cell
colors.
Here's the column headers:
int colCount = 1;
foreach (var key in IndexedIgColumnNames.Keys)
{
Tuple<string, PropertyInfo, PropertyInfo, CellInfo> t;
if (IndexedIgColumnNames.TryGetValue(key, out t))
{
xls.SetCellValue(celly, cellx, t.Item1);
var fmt = xls.GetCellVisibleFormatDef(celly, cellx);
fmt.Borders.Left.Style = TFlxBorderStyle.Thin;
fmt.Borders.Left.Color = TExcelColor.Automatic;
fmt.Borders.Right.Style = TFlxBorderStyle.Thin;
fmt.Borders.Right.Color = TExcelColor.Automatic;
fmt.Borders.Top.Style = TFlxBorderStyle.Thin;
fmt.Borders.Top.Color = TExcelColor.Automatic;
fmt.Borders.Bottom.Style = TFlxBorderStyle.Thin;
fmt.Borders.Bottom.Color = TExcelColor.Automatic;
fmt.HAlignment = t.Item4.HAlignment;
fmt.VAlignment = TVFlxAlignment.center;
fmt.Font.Style = TFlxFontStyles.Bold;
fmt.WrapText = t.Item4.WordWrap;
if (t.Item4.Width > 0)
xls.SetColWidth(colCount, t.Item4.Width);
xls.SetCellFormat(celly, cellx, xls.AddFormat(fmt));
colCount++;
}
cellx++;
Putting the data in:
foreach (var key in IndexedIgColumnNames.Keys)
{
Tuple<string, PropertyInfo, PropertyInfo, CellInfo> t;
if (IndexedIgColumnNames.TryGetValue(key, out t))
{
var propValue = t.Item2;
//Setup cell format/color here
xls.SetCellValue(celly, cellx, PropertyHelper.GetValueAsString(sched, propValue));
var fmt = xls.GetCellVisibleFormatDef(celly, cellx);
fmt.Borders.Left.Style = TFlxBorderStyle.Thin;
fmt.Borders.Left.Color = TExcelColor.Automatic;
fmt.Borders.Right.Style = TFlxBorderStyle.Thin;
fmt.Borders.Right.Color = TExcelColor.Automatic;
fmt.Borders.Top.Style = TFlxBorderStyle.Thin;
fmt.Borders.Top.Color = TExcelColor.Automatic;
fmt.Borders.Bottom.Style = TFlxBorderStyle.Thin;
fmt.Borders.Bottom.Color = TExcelColor.Automatic;
fmt.FillPattern = new TFlxFillPattern();
byte[] bytes = BitConverter.GetBytes(PropertyHelper.GetIntValue(sched, t.Item3));
fmt.FillPattern.BgColor = TUIColor.FromArgb(bytes[1], bytes[2], bytes[3]); ;
fmt.HAlignment = t.Item4.HAlignment;
fmt.VAlignment = TVFlxAlignment.center;
fmt.Font.Style = TFlxFontStyles.Bold;
fmt.WrapText = t.Item4.WordWrap;
xls.SetCellFormat(celly, cellx, xls.AddFormat(fmt));
}
cellx++;
}
cellx = x;
celly++;
The
"PropertyHelper.GetValueAsString()" is a static class that reads the
property value from the object in question, using the property map I
setup. The properties used is dynamic and that's the reason why I'm
using it.
I'm not able to share the data.
It's pulled off of a web service, and prior to that it's pulled out of a
database and a lot happens between the database and what's displayed.
As
far as setting the cell value and the cell format in the code above, is
there anything there that jumps out at you? Am I assigning things in
the wrong order?
It prints correctly, that's what's odd about it.
Thanks,
Curt