//添加引用
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
方法一:将识别结果写入到Excel表格中(根据指定模版写入,并将其以当前保存时间命名另存)
//**********************************************************/
方法二:将识别结果写入到Excel表格中(在指定模版上直接写入)
//1.创建Applicaton对象
Excel.Application xApp = new Excel.Application();
xApp.Visible = true;
//2.得到workbook对象,可以用两种方式之一:下面是打开已有的文件
//Excel.Workbook xBook = xApp.Workbooks.Open(@"E:\5_调试软件\ThinkCamWorkstation\PassData\192.168.116.248\2015-08-06\18\result.xlsx",
Excel.Workbook xBook = xApp.Workbooks.Open(path + "\\result.xlsx",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
//3.指定要操作的Sheet
Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
//4.写入数据
Excel.Range carAmount = xSheet.get_Range("J4", Missing.Value);
carAmount.Value2 = total;
carAmount.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range invalid_license_plate = xSheet.get_Range("M4", Missing.Value);
invalid_license_plate.Value2 = invalid;
invalid_license_plate.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range chinese_character_wrong = xSheet.get_Range("N4", Missing.Value);
chinese_character_wrong.Value2 = wrongCH;
chinese_character_wrong.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range letter_wrong = xSheet.get_Range("O4", Missing.Value);
letter_wrong.Value2 = wrongEN;
letter_wrong.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range number_wrong = xSheet.get_Range("P4", Missing.Value);
number_wrong.Value2 = wrongNU;
number_wrong.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range recognition_wrong = xSheet.get_Range("Q4", Missing.Value);
recognition_wrong.Value2 = wrongCL;
recognition_wrong.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range wrong_amount = xSheet.get_Range("T4", Missing.Value);
wrong_amount.Value2 = wrong;
wrong_amount.Interior.ColorIndex = 3; //设备Range的背景色
Excel.Range right_amount = xSheet.get_Range("U4", Missing.Value);
right_amount.Value2 = right;
right_amount.Interior.ColorIndex = 3; //设备Range的背景色
//5.保存保存WorkBook
xBook.Save();
//6.从内存中关闭Excel对象
xSheet = null;
xBook = null;
xApp.Quit(); //这一句非常重要,否则Excel对象不能从内存中退出
xApp = null;
MessageBox.Show(summary, "提示", MessageBoxButtons.OK);