/// <summary>
public void WriteData(string data,string sheetName, int row, int column) { try {
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象 object missing = System.Reflection.Missing.Value;//获取缺少的object类型值 //打开指定的Excel文件 excel.Application.DisplayAlerts = false;//不显示提示对话框
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(sheetName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);//打开Excel Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;//实例表格 Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets[1];//第一个表格
worksheet.Cells[row,column].value = data; workbook.Save();//保存工作表 workbook.Close(false, missing, missing);//关闭工作表 } catch (Exception e) { MessageBox.Show(e.Message.ToString()); }
}
|
请发表评论