Microsoft.Office.Interop.Excel.Application excelApp = null;
Microsoft.Office.Interop.Excel.Workbook workBook;
Microsoft.Office.Interop.Excel.Worksheet ws = null;
try
{
excelApp = new Microsoft.Office.Interop.Excel.Application();
string url = @"F:\Customs\Excharge\报文计费工具\PtsCost\" + payPackage + ".xls";
workBook = excelApp.Workbooks.Open(url,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
ws = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Worksheets[1];
ws.Cells[7, 9] = serialNo;
ws.Cells[14, 4] = tradeName;
DateTime date = DateTime.Parse(yyyymm.Substring(0,4)+"-"+yyyymm.Substring(4,2) + "-01");
ws.Cells[16, 4] = date.ToString("yyyy-MM-dd");
ws.Cells[48, 8] = ws.Cells[16, 7] = date.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
if (dicEmlDetail.ContainsKey(Common.EML213))
{
ws.Cells[21, 8] = dicEmlDetail[Common.EML213];
}
else
{
ws.Cells[21, 8] = 0;
}
if (dicEmlDetail.ContainsKey(Common.EML221))
{
ws.Cells[22, 8] = dicEmlDetail[Common.EML221];
}
else
{
ws.Cells[22, 8] = 0;
}
if (dicEmlDetail.ContainsKey(Common.EML223))
{
ws.Cells[23, 8] = dicEmlDetail[Common.EML223];
}
else
{
ws.Cells[23, 8] = 0;
}
if (dicEmlDetail.ContainsKey(Common.EML311))
{
ws.Cells[24, 8] = dicEmlDetail[Common.EML311];
}
else
{
ws.Cells[24, 8] = 0;
}
if (dicEmlDetail.ContainsKey(Common.EML321))
{
ws.Cells[25, 8] = dicEmlDetail[Common.EML321];
}
else
{
ws.Cells[25, 8] = 0;
}
if (dicEmlDetail.ContainsKey(Common.EML411))
{
ws.Cells[26, 8] = dicEmlDetail[Common.EML411];
}
else
{
ws.Cells[26, 8] = 0;
}
ws.Cells[31, 6] = sumEmlCount;
if (payPackage == Common.B套餐)
{
ws.Cells[33, 6] = sumEmlCount - 20 > 0 ? sumEmlCount - 20 : 0;
}
else
{
ws.Cells[32, 6] = sumEmlCount;
}
url = @"F:\Temp\" + payPackage +tradeName+ DateTime.Now.ToString("yyyyMMddHHmmsss") + ".xls";
//ws.SaveAs(url,
// Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
// Missing.Value, Missing.Value, Missing.Value, Missing.Value);
workBook.Saved = true;
workBook.SaveCopyAs(url);
workBook.Close();
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
ws = null;
workBook = null;
excelApp = null;
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("Excel"))
{
if (!p.CloseMainWindow())
{
p.Kill();
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
评论列表: