开发者

Name a cell with POI

开发者 https://www.devze.com 2023-03-29 01:11 出处:网络
In normal excel one can name a cell (or a range) using the little text box in the top left part of the sheet, so for example one could name a cell from H13 to \"total\".

In normal excel one can name a cell (or a range) using the little text box in the top left part of the sheet, so for example one could name a cell from H13 to "total".

Is there a way to do that through Apache开发者_如何学运维 POI?


From the POI 'Busy Developer's User Guide'

// setup code
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet(sname);
sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);

// 1. create named range for a single cell using areareference
Name namedCell = wb.createName();
namedCell.setNameName(cname);
String reference = sname+"!A1:A1"; // area reference
namedCell.setRefersToFormula(reference);
0

精彩评论

暂无评论...
验证码 换一张
取 消