日期:2014-05-17 浏览次数:20923 次
private void AutoWriteToExcel()//向Excel表格中写入数据
{
System.Reflection.Missing miss = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.ApplicationClass Excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbooks books = (Microsoft.Office.Interop.Excel.Workbooks)Excel.Workbooks;
int k = 0;
IntPtr intptr = new IntPtr(Excel.Hwnd);
if (IsFirstLoad==true) //第二次写入时直接打开第一新建的表格
{
Microsoft.Office.Interop.Excel.Workbook book = books.Open(FileName, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet;
Microsoft.Office.Interop.Excel.Range range = null;
int Row = sheet1.UsedRange.Count/3;
range = sheet1.UsedRange;
//range = sheet1.get_Range;
string[,] objVal = new string[4, 4];
for (int i = 0; i < this.listView1.Columns.Count; i++)
{
objVal[0, i] = this.listView1.Columns[i].Text;
}
for (int i = 0; i < 3; i++)
{
for (int j&n