1. 引用的com组件:Microsoft.Office.Interop.Excel.dll,一般安装完office就有这个文件。(office 2003下载这个dll:点击下载)。
  2. 新建一个C#项目,添加前面的dll到引用里面来
  3. 读取excel数据到dataset
    方法一
    C#操作excelprivate void OpenExcel(string strFileName)
            }

    方法二
    C#操作excel public DataSet ExcelToDS(string Path)
  4. dataset导出到excel
    4.1 写数据
    C#操作excel  object missing = System.Reflection.Missing.Value;
    C#操作excel            Microsoft.Office.Interop.Excel.ApplicationClass appc 
    = new Microsoft.Office.Interop.Excel.ApplicationClass();//lauch excel
    C#操作excel
                Microsoft.Office.Interop.Excel.Workbook wb = appc.Application.Workbooks.Add(true);//add new workbook            Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.get_Item(1);//get first worksheet
    C#操作excel
                Microsoft.Office.Interop.Excel.Range range = ws.get_Range("A1""C1");//get range from A1 to C1
    .
    或者
    C#操作excelpublic bool SaveFP2toExcel(string Path)
    4.2 格式化
    设置字体颜色
    C#操作excelrange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);//white color
    设置背景色
    C#操作excelrange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.MidnightBlue);//set backgroud color

相关文章:

  • 2022-02-07
  • 2022-01-29
  • 2021-09-18
  • 2021-08-22
猜你喜欢
  • 2021-12-02
  • 2021-06-04
  • 2022-01-06
  • 2021-11-03
相关资源
相似解决方案