2 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個贊
如果*.xlsx文件應(yīng)另存為,則存儲在其中的*.xltx部件名稱的內(nèi)容類型也必須更改為. 沒有合適的。但這也可以使用低級別的類來完成。/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貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個贊
ActiveWorkbook.saveas filename:=replace(activeworkbook.name,".xlsx",".xlst"),fileformat:=54
對于沒有宏或
ActiveWorkbook.SaveAs Filename:=Replace(ActiveWorkbook.Name, ".xlsm", ".xltm"), FileFormat:=53
如果你有宏
添加回答
舉報