Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i use the following part of the code to export the data to excel
public void GenerateSimulatorFile(XmlDocument doc)
{
AddHashKey(doc);
XmlNodeList ndHashKeyList = doc.SelectNodes("//Configuration[not(HashKey=preceding-sibling::Configuration/HashKey)]/HashKey");

Excel.Application xla = new Excel.Application();
xla.Visible = true;
Excel.Workbook wb = xla.Workbooks.Add(Excel.XlSheetType.xlWorksheet);
int k = 1;
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[k];
if (ndHashKeyList.Count>0)
{
foreach (XmlNode ndHashKey in ndHashKeyList)
{
if (k > 1)
{
wb.Worksheets.Add(Type.Missing, ws, wb.Worksheets.Count, Type.Missing);
ws = (Excel.Worksheet)wb.Worksheets[k];
}
k++;
string hashkey = ndHashKey.InnerText;
ws.Cells[1, 1] = "Configuration Name";
ws.Cells[1, 2] = "Array Model";
ws.Cells[1, 3] = "Raid Type";
ws.Cells[1, 4] = "Disk Type";
ws.Cells[1, 5] = "Microcode Rev";
ws.Cells[1, 6] = "Test Phase Name";
ws.Cells[1, 7] = "Test Type";

XmlNode configNode = doc.SelectSingleNode("//Configuration[HashKey='" + hashkey + "']");
ws.Cells[2, 1] = (configNode.SelectSingleNode("ConfigurationName").InnerText);
ws.Cells[2, 2] = (configNode.SelectSingleNode("ArrayModel").InnerText);
ws.Cells[2, 3] = (configNode.SelectSingleNode("RaidType").InnerText);
ws.Cells[2, 4] = (configNode.SelectSingleNode("DiskType").InnerText);
ws.Cells[2, 5] = (configNode.SelectSingleNode("MicrocodeRev").InnerText);
ws.Cells[2, 6] = (configNode.SelectSingleNode("TestPhaseName").InnerText);
ws.Cells[2, 7] = (configNode.SelectSingleNode("TestType").InnerText);

ws.Cells[4, 1] = "I/O";
ws.Cells[4, 2] = "Response Time";

XmlNodeList ndList = doc.SelectNodes("//Configuration[HashKey='" + hashkey + "' and ParentMetric='IOsps']");
string[,] intervalValue = new string[2, ndList.Count];
int i = 0;
foreach (XmlNode nd in ndList)
{
ws.Cells[i + 5, 1] = nd.SelectSingleNode("IntervalValue").InnerText;
i++;
}
ndList = doc.SelectNodes("//Configuration[HashKey='" + hashkey + "' and ParentMetric='RT']");
i = 0;
foreach (XmlNode nd in ndList)
{
ws.Cells[i + 5, 2] = nd.SelectSingleNode("IntervalValue").InnerText;
i++;
}
/****** Creating the chart object*******/
Excel.ChartObjects chartObjs = (Excel.ChartObjects)ws.ChartObjects(Type.Missing);
Excel.ChartObject chartObj = chartObjs.Add(300, 60, 300, 300);
Excel.Chart xlChart = chartObj.Chart;

/**********draw the chart****/
Excel.Range chartRange = ws.get_Range("A4", ws.Cells[4 + i, 2]);
xlChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterSmoothNoMarkers;
xlChart.SetSourceData(chartRange, Type.Missing);
xlChart.HasTitle = true;
xlChart.ChartTitle.Text = "Response Tiime";
}
/********* relase the object that are created*******/
releaseObject(ws);
releaseObject(wb);
releaseObject(xla);
}
else
{
ws.Cells[1, 1] = "NO RESULTS FOUND";
}






The data and every thing is fine and i also have installed microsoft office 2007 version also on the deployment server i can't see any errors or the data being exported to excel can i get help on this.
Posted

1 solution

It's a bad idea to install office on a server especially a web server and fire up office applications in the background.

Try using a library like : http://epplus.codeplex.com/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900