// Loop for the creating table columns in excel and assigning the values in cells
for (i = 0; i <= widget.Views[viewIndex].Data.Table.ColumnHeadings.Count - 1; i++)
{
cells[0, i].PutValue(widget.Views[viewIndex].Data.Table.ColumnHeadings[i]);
Style style = cells[0, i].GetStyle();
style.Font.IsBold = true;
//style.BackgroundColor = Color.Gray;
cells[0, i].SetStyle(CreateBorderForTable(style));
}
int j = 0;
int z = 0;
// Loop for the creating table rows in excel and assigning the values in cells
for (i = 1; i <= widget.Views[viewIndex].Data.Table.Rows.Count; i++)
{
for (j = 0; j <= widget.Views[viewIndex].Data.Table.ColumnHeadings.Count - 1; j++)
{
string[] result = widget.Views[viewIndex].Data.Table.Rows[z];
if (j == 0)
{
if (result[j] != null && result[j] != "null")
{
checkCellValue = result[j];
if (checkCellValue.Contains("%"))
{
string cellValue = checkCellValue.Replace("%", "");
decimal temp = 0m;
if (decimal.TryParse(cellValue, out temp))
{
cells[i, j].PutValue((Convert.ToDecimal(cellValue)) / 100);
Style st = cells[i, j].GetStyle();
if (widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatPercentiles || widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatPercentile)
{
st.Number = 10;
}
else if (widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatDecimal)
{
st.Number = 2;
}
else
{
}
cells[i, j].SetStyle(CreateBorderForTable(st));
}
else
{
cells[i, j].PutValue(checkCellValue);
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
}
else
{
DateTime dDate;
if (DateTime.TryParse(checkCellValue, out dDate))
{
String.Format("{0:d/MM/yyyy}", dDate);
// change the string in to date format
string[] dateArray = checkCellValue.Split('/');
DateTime dt = new DateTime(Convert.ToInt16(dateArray[2]), Convert.ToInt16(dateArray[1]), Convert.ToInt16(dateArray[0]));
string date = String.Format("{0:y}", dt);
// again changing the date to liek March,2010 format
cells[i, j].PutValue(date);
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
else
{
cells[i, j].PutValue(result[j]);
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
}
}
else
{
cells[i, j].PutValue(0.0);
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
}
else
{
if (result[j] != null && result[j] != "null")
{
if (result[j].Contains("%"))
{
string cellValue = result[j].Replace("%", "");
cells[i, j].PutValue((Convert.ToDecimal(cellValue)) / 100);
Style st = cells[i, j].GetStyle();
if (widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatPercentiles || widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatPercentile)
{
st.Number = 10;
}
else if (widget.Views[viewIndex].Data.ValueFormat == ChartTypeValueFormatDecimal)
{
st.Number = 2;
}
else
{
}
cells[i, j].SetStyle(CreateBorderForTable(st));
}
else
{
cells[i, j].PutValue(Convert.ToDecimal(result[j]));
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
}
else
{
cells[i, j].PutValue(0.0);
Style st = cells[i, j].GetStyle();
cells[i, j].SetStyle(CreateBorderForTable(st));
}
}
}
z++;
}
rowIndex = widget.Views[viewIndex].Data.Table.Rows.Count + 1;
string cellname = CellsHelper.CellIndexToName(widget.Views[viewIndex].Data.Table.Rows.Count, widget.Views[viewIndex].Data.Table.ColumnHeadings.Count - 1);
chart.NSeries.Add("Data!B2:" + cellname, true);
chart.NSeries.CategoryData = "Data!A2:A" + rowIndex.ToString();
chart.NSeries.IsColorVaried = false;