以下是一些对excel的一些基本操作:
命名控件的引入: using Microsoft.office.Interop.Excel;
列表内容:如果是对一个已经存在的excel文件进行操作则:
Application app=new Application();
Workbook wbook=app.Workbooks.Open("c:\temp.xls",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);
Worksheet worksheet=(Worksheet)wbook.Worksheets[1];
3:如果是新建一个excel文件:
Application app=new Application();
Workbook wbook=app.Workbooks.Add(Type.Missing);
Worksheet worksheet=(Worksheet)wbook.Worksheets[1];
4:设置某个单元格里的内容:
worksheet.Cells[1,2]="列内容"
5.读取某个单元格里的内容
string temp=((Range)worksheet.Cells[1,2]).Text;
6.设置某个单元格里的格式
Excel.Range rtemp=worksheet.get_Range("A1","A1");
rtemp.Font.Name="宋体";
rtemp.Font.FontStyle="加粗";
rtemp.Font.Size=5;
7.保存新建的内容:
worksheet.SaveAs("c:\temp.xls",Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);