日期:2014-05-17 浏览次数:20951 次
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Age");
dt.Columns.Add("Sex");
DataRow dr = dt.NewRow();
dr["ID"] = "1001";
dr["Name"] = "李明";
dr["Age"] = "15";
dr["Sex"] = "男";
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["ID"] = "1002";
dr1["Name"] = "Janney";
dr1["Age"] = "15";
dr1["Sex"] = "女";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2["ID"] = "1003";
dr2["Name"] = "Daneey";
dr2["Age"] = "15";
dr2["Sex"] = "男";
dt.Rows.Add(dr2);
Microsoft.Office.Interop.Owc11.SpreadsheetClass sheet = new Microsoft.Office.Interop.Owc11.SpreadsheetClass();
ChartSpace myspace = new ChartSpace();
OWC.SpreadsheetClass myexcel = new OWC.SpreadsheetClass();
OWC.Worksheet mysheet = myexcel.ActiveSheet;
mysheet.Cells[1, 1] = "报表测试";
for (int i = 0; i < dt.Columns.Count; i++)
{
mysheet.Cells[2, 1 + i] = dt.Columns[i].Caption;
}
for (int j = 0; j <