• Excel:写入Excel单纯写入


    //创建一个Excel.Application的新进程
    Microsoft.Office.Interop.Excel.Application app = new Application();
    if (app == null) return;
    app.Visible = false;
    app.UserControl = true;
    Workbooks workbooks = app.Workbooks;
    _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);//这里的Add方法里的参数就相当于继承了一个空模板(暂这样理解吧)
    Sheets sheets = workbook.Worksheets;
    _Worksheet worksheet = (_Worksheet)sheets.get_Item(1);
    if (worksheet == null) return;
    worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 3]).Merge(Type.Missing);//横向合并
    worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 1]).Value2 = "导出EXCEL测试1";

    worksheet.Cells[2, 1] = "序号";
    worksheet.Cells[2, 2] = "公司";
    worksheet.Cells[2, 3] = "部门";

    worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[2, 3]).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
    int rowNum = 0;
    for (int i = 0; i < 100; i++)
    {
        rowNum = i + 1;
        worksheet.Cells[3 + i, 1] = rowNum;
        worksheet.Cells[3 + i, 2] = "公司" + (i + 1);
        worksheet.Cells[3 + i, 3] = "部门" + (i + 1);
        worksheet.get_Range(worksheet.Cells[3 + i, 1], worksheet.Cells[3 + i, 3]).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);//设置边框颜色
    }
    worksheet.Name = "导出Excel测试1";
    string tick = DateTime.Now.Ticks.ToString();
    string save_path = "\\" + tick + ".xls";

    workbook.SaveAs(save_path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);       

  • 相关阅读:
    html5 video标签如何禁止视频下载
    Redis源代码-数据结构Adlist双端列表
    HTML5分析实战WebSockets基本介绍
    Chromium on Android: Android在系统Chromium为了实现主消息循环分析
    Android AIDL使用特定的解释
    [LeetCode]Maximum Product Subarray
    OC省字典的数组摘要集
    CocoaChina 第四个测试
    Java在的时候,类定义HashSet初始化方法
    WSHPSRS-匹克选择列表生成器-SRS(R12.2.3)
  • 原文地址:https://www.cnblogs.com/pnljs/p/2363115.html
Copyright © 2020-2023  润新知