/// <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());
}

}

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2021-04-29
  • 2022-12-23
  • 2021-08-22
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案