c#如何打开现有excel表并向其中一行一行的添加信息

写一个调用函数
public static void WriteResultExcel(string ExcelSheetPath, string keywords, string time, string filepath, string lineindex, string AbnormalIfo, string Package)
{}
{}中实现打开ExcelSheetPath路径下的excel表格,此被调函数每被调一次就在excel表格的下一行添加一行string keywords, string time, string filepath, string lineindex, string AbnormalIfo, string Package这些string信息,其中keywords占excel表的第一列,time为第二列,依次类推

string excelName= ExcelFileUrl();//返回Excel的路径
string fileName = AppDomain.CurrentDomain.BaseDirectory.ToString() + excelName;//保存Excle的文件路径
object missing = Missing.Value;
Microsoft.Office.Interop.Excel.Application appExcel = null;//实例Excel类
try
{
appExcel = new Microsoft.Office.Interop.Excel.Application();
appExcel.DisplayAlerts = false;//DisplayAlerts 属性设置成 False,就不会出现这种警告。
Microsoft.Office.Interop.Excel.Workbook workbook = appExcel.Workbooks.Open(fileName,
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.Workbooks workbooks = appExcel.Workbooks;//
//Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(missing);//工作簿
Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Worksheets;//实例表格
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets[1];//第一个表格

}
catch
{}
类的传值如传的是第一个表格类型是Microsoft.Office.Interop.Excel.Worksheet 的函数
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-02-13
上传了一个示例,运行截图和项目附件在这里:
http://zhidao.baidu.com/question/872221578070843972.html
希望对你有帮助,还有疑问请追问或是百度Hi上留言
第2个回答  2014-02-17
建议参考下pageoffice
相似回答