2 回答
TA贡献1827条经验 获得超9个赞
如果*.xlsx文件应另存为,则存储在其中的*.xltx部件名称的内容类型也必须更改为. 没有合适的。但这也可以使用低级别的类来完成。/xl/workbook.xml[Content_Types].xmlapplication/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xmlXSSFWorkbookTypeXLTX
例子:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
class ExcelWriteXLTX {
public static void main(String[] args) throws Exception {
try (Workbook workbook = new XSSFWorkbook();
FileOutputStream fileout = new FileOutputStream("ExcelTemplate.xltx") ) {
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellValue("Content in template");
// ...
((XSSFWorkbook)workbook).getPackagePart().setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml");
workbook.write(fileout);
}
}
}
TA贡献1842条经验 获得超21个赞
ActiveWorkbook.saveas filename:=replace(activeworkbook.name,".xlsx",".xlst"),fileformat:=54
对于没有宏或
ActiveWorkbook.SaveAs Filename:=Replace(ActiveWorkbook.Name, ".xlsm", ".xltm"), FileFormat:=53
如果你有宏
添加回答
举报