的
CTXf,也是
quotePrefix财产的一部分
XSSFCellStyle,而不是
XSSFCell。
因此,我们必须创建一个
XSSFCellStyle,在
quotePrefix那里
设置,然后将其
XSSFCellStyle应用于
XSSFCell。
import org.apache.poi.ss.usermodel.*;import org.apache.poi.xssf.usermodel.*;import java.io.FileOutputStream;import java.io.IOException;class WriteQuotePrefix { public static void main(String[] args) { try { Workbook wb = new XSSFWorkbook(); CellStyle style = wb.createCellStyle(); ((XSSFCellStyle)style).getCoreXf().setQuotePrefix(true); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellStyle(style); cell.setCellValue("1234"); FileOutputStream fileOut = new FileOutputStream("WriteQuotePrefix.xlsx"); wb.write(fileOut); fileOut.close(); } catch (IOException ioex) { } }}


