如何對ExcelPlate中某一行設定格式?
ExcelPlate 的格式是要求先設定的,所以對於這種需求,需要另外寫代碼來實現.
如:對A1單元格畫底線,範例代碼如下:
需要添加Excel.dll引用,可以在OfficeTools下找到
using System.Reflection;
using System.Runtime.InteropServices;
string file = @"c:\test.xls";//xls的檔案名
Excel.Application application = new Excel.Application();//打開Excel進程
Excel.Workbook workBook = null;
Excel.Worksheet workSheet = null;
Excel.Range cell = null;
try
{
application.Visible = false;//不顯示Excel程式
application.DisplayAlerts = false;//不顯示確認窗口
workBook = application.Workbooks.Open(file, 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);//打開文件
workSheet = workBook.Worksheets[1] as Excel.Worksheet;//取得第一個WorkSheet
cell = workSheet.get_Range("A1", "A1");//取得A1這個單元格
cell.Font.Underline = true;//設置下劃線
workBook.Save();//保存檔
}
finally
{
application.Quit();//退出Excel進程
Marshal.ReleaseComObject(application);//釋放Excel進程
Marshal.ReleaseComObject(workBook);//釋放Excel進程
Marshal.ReleaseComObject(workSheet);//釋放Excel進程
Marshal.ReleaseComObject(cell);//釋放Excel進程
application = null;
workBook = null;
workSheet = null;
cell = null;
GC.Collect();//回收
}