zoukankan      html  css  js  c++  java
  • 导出到Excel,更改导出的Style

    static void inputExcel(Args _args)
    {
    #Excel
    str path;
    str name;
    // DBTransQueryTmp tmpData;
    SysExcel sysexcel;
    SysExcelApplication excel;
    SysExcelWorkbooks books;
    SysExcelWorkbook book;
    SysExcelWorkSheets sheets;
    SysExcelWorkSheet sheet;
    SysExcelCells cells;
    SysExcelRange range;
    COM booksave;
    COM range2;

    SysExcelStyles styles;
    SysExcelStyle style;
    SysExcelFont font;
    ;
    path = DateTimeUtil::toStr(DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(),Timezone::GMTPLUS0800BEIJING_CHONGQING_HONGKONG));
    path = strkeep(path,"0123456789");
    path = strfmt("d:\%1.xls",path); //获取当前时间做Excel名
    name = strfmt("%1",DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(),Timezone::GMTPLUS0800BEIJING_CHONGQING_HONGKONG)));

    Winapi::createFile(path);
    if (Winapi::fileExists(path))
    {
    excel = SysExcelApplication::construct();
    excel.visible(true);
    books = excel.workbooks();
    books.open(path);
    book = books.item(1);
    sheets = book.worksheets();
    sheet = sheets.itemFromNum(1);
    cells = sheet.cells();

    styles = book.styles();
    style = styles.add("a");
    font = style.font();
    font.bold(true);
    font.comObject().size("40");

    style = styles.add("b");//设定“b”的style,在后面的sheet中调用
    font = style.font();
    font.bold(true);
    font.color(188);
    font.comObject().size("30");

    range = cells.range("A1:P1"); //合并第一行A - P
    range.comObject().merge();
    range.style("a");
    range.horizontalAlignment(3);

    cells.item(1,1).value("This is Bold Title!"); // 给第一行第一列赋值
    cells.item(2,1).value("red color"); // 给第二行第一列赋值
    cells.item(2,7).value("red color"); // 给第二行第七列赋值
    cells.item(3,1).value("general"); //给第三行一列赋值
    sheet.range("A2").style("b");
    sheet.range("A3").style("b"); // 调用前面定义的style
    }
    }

  • 相关阅读:
    MSchart设置网格线
    搭建ELDK交叉编译环境
    Virtualbox设置共享文件夹的方法
    VS2010自动关闭问题的解决方法
    如何让PHPCms内容页支持JavaScript
    Phpcms V9 调用全站最新文章的代码
    Phpcms V9 调用随机文章的方法
    VMware下Ubuntu不能和主机共享文件夹的解决方法
    Xshell无法连接Ubuntu的解决办法
    Phpcms V9 调用全站文章排行的解决方案
  • 原文地址:https://www.cnblogs.com/KobeZhang/p/3696340.html
Copyright © 2011-2022 走看看