write to xlsm (Excel 2007) using apache poi

POI的下载(记得把其中的jar包全部加到工程里哦)http://mirror.bit.edu.cn/apache/poi/

I have written java file for writing xlsm(Excel 2007).

Using Apache POI Library, Writing xlsx file is success. And Writing xlsm file is success. But I can't open the xlsm file because of error when open xlsm file.

Would it feasible to write xlsm file using Apache POI Library?

If it is feasible to write xlsm, Please kindly provide guide line How to write xlsm file using Apache poi library.

XSSFWorkbook workBook = new XSSFWorkbook();
XSSFSheet sheet = workBook.createSheet("Related_SRC");
String realName = "Test.xlsm";
File file = new File("C:\\sdpApp", realName);
try {
    FileOutputStream fileOutput = new FileOutputStream(file);
        workBook.write(fileOutput);
        fileOutput.close();
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

Thanks

According to the documentation of Apache POI it is not possible to create macros:http://poi.apache.org/spreadsheet/limitations.html

However it's possible to read and re-write files containing macros and apache poi will safely preserve the macros.

Here is an example:

String fileName = "C:\\new_file.xlsm";

try {

    Workbook workbook;
    workbook = new XSSFWorkbook(
        OPCPackage.open("resources/template_with_macro.xlsm")
    );

    //DO STUF WITH WORKBOOK

    FileOutputStream out = new FileOutputStream(new File(fileName));
    workbook.write(out);
    out.close();
    System.out.println("xlsm created successfully..");

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (InvalidFormatException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

The file that is created will not give you an error

Java操作Excel: POI不能创建xlsm问题的方法(源自StackOverFlow)的更多相关文章

  1. Java操作Excel之POI简单例子

    /** * 利用POI操作Excel表单 * * 需要jar包: * HSSF针对03及以前版本,即.xls后缀 * |---poi-3.16.jar * XSSF针对07及以后版本,即xlsx后缀 ...

  2. java操作Excel、PDF文件

    java操作Excel.PDF文件 分享者:Vashon 分享来源:CSDN博客 下面这些是在开发中用到的一些东西,有的代码贴的不是完整的,只是贴出了关于操作EXCEL的代码: jxl是一个*国人写的 ...

  3. java操作excel 工具类

    java操作excel 可参考https://blog.csdn.net/xunwei0303/article/details/53213130 直接上代码: 一.java生成excel文件: pac ...

  4. Java 操作 EXCEL

    今天帮朋友写了一段用来处理EXCEL内容的程序,在这里记录下自己的学习过程.主要是对EXCEL表格中的内容做分类和统计,使用计算机来做这种重复的机械性地工作再好不过了.首先,我们需要下载一个java操 ...

  5. java操作Excel处理数字类型的精度损失问题验证

    java操作Excel处理数字类型的精度损失问题验证: 场景: CELL_TYPE_NUMERIC-->CELL_TYPE_STRING--->CELL_TYPE_NUMERIC POI版 ...

  6. jxl的使用总结(java操作excel)

    jxl.jar是通过java操作excel表格的工具类库: jxl.jar包:链接:http://pan.baidu.com/s/1o8qFJHw 密码:5jyq 1:通过模拟实现创建一个表格,然后模 ...

  7. Java操作Excel文件以及在Android中的应用

    本文章由临江仙原创,转载请注明出处:http://blog.csdn.net/zhy_cheng/article/details/10286563 Excel作为一种有格式的文件,可以使用Java来对 ...

  8. 【转载】jxl的使用总结(java操作excel)

    jxl.jar是通过java操作excel表格的工具类库: 链接:https://pan.baidu.com/s/1AAT_eA_Q47zFeQohap6eQg 提取码:777b 1:通过模拟实现创建 ...

  9. JAVA操作Excel时文字自适应单元格的宽度设置方法

    使用JAVA操作Excel通常都使用JXL,方法很简单网上也有很多的教程,然后往往一些细节性的问题却导致我们这些Programmer苦恼不已.这两天帮一个朋友做一个Excel表格自动生成的小软件,就遇 ...

随机推荐

  1. CodeForces 520B Two Buttons(用BFS)

     Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #279 (Div. 2) vector

    A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. 【BFS】POJ 3278

    POJ 3278 Catch That Cow 题目:你要去抓一头牛,给出你所在的坐标和牛所在的坐标,移动方式有两种:要么前一步或者后一步,要么移动到现在所在坐标的两倍,两种方式都要花费一分钟,问你最 ...

  4. BZOJ1098: [POI2007]办公楼biu

    从问题可以看出是求补图的连通块及点数 但补图太大.所以考虑缩小规模. 当一个点归属于一个连通块后,它以后就不需要了.所以可以用链表,删去这个点,也就减小了规模. 一个点开始bfs,每个点只会进队一次, ...

  5. weinre targets none 的问题

    安装了weinre之后,target 老是是none.问题就是处在localhost或者127.0.0.1. 因为手机或者虚拟机要通讯,相当于另外一台电脑,用localhost怎么能实现通讯嘛.得用本 ...

  6. ArcEngine奇怪异常:HRESULT:0x80040351

    错误如图 根据该博客,http://blog.csdn.net/u011609113/article/details/51155116, 显示该错误为Duplicate Field Names wit ...

  7. 从DataGridView导出Excel

    从DataGridView导出Excel的两种情况,不多说,直接记录代码(新建类,直接引用传入参数). using System; using System.Collections.Generic; ...

  8. windows下读取磁盘扇区数据

    在Windows下,磁盘可以看做是一个文件,其文件名为\\\\.\\PhysicalDriveX,其中X表示磁盘的编号,例如\\\\.\\PhysicalDrive0表示的是第0号磁盘,如果需要读取一 ...

  9. 多边形裁剪的Sutherland-Hodgman算法

    多边形裁剪是渲染管线中重要的一个子阶段,它将视截体外的多边形去除.一种简单的裁剪策略是一旦发现一个顶点在裁剪区域以外,就立刻丢弃该多边形.更加精细的做法则是,将原来的多边形拆为多个不跨越边界的多边形, ...

  10. SOA架构设计(转发)

    阅读目录: 1.背景介绍 2.SOA的架构层次 2.1.应用服务(原子服务) 2.2.组合服务 2.3.业务服务(编排服务) 3.SOA化的重构 3.1.保留服务空间,为了将来服务的组合 4.运用DD ...