iT邦幫忙

0

java poi匯出excel時,是否有註解功能,或是否有其他套件可以使用

  • 分享至 

  • xImage

目前使用poi套件,需要將資料庫資料匯出成excel,其中需要有註解的功能

不過目前只找得到備註的寫法
Comment comment = sheet.createDrawingPatriarch().createCellComment(xssfClientAnchor);

https://ithelp.ithome.com.tw/upload/images/20230602/20160635AZcxmJKECE.jpg

想請問poi是否不支援註解,只有支援備註?
有其他套件有支援excel的註解功能嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2023-06-04 09:17:19

看看這篇合不合用

u9934001 iT邦新手 5 級 ‧ 2023-06-08 12:47:08 檢舉

感謝回答,不過這篇看起來也只有提到備註,沒有註解功能

那就試試jexcelapi

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;

// Load the Excel file
Workbook workbook = Workbook.getWorkbook(new File("path/to/your/file.xls"));

// Get the desired sheet
Sheet sheet = workbook.getSheet(0);

// Get the cell and its note
Cell cell = sheet.getCell(colNum, rowNum);
String note = cell.getNote();

if (note != null) {
    System.out.println("Cell note: " + note);
}

// Close the workbook
workbook.close();

// Load the Excel file
Workbook workbook = Workbook.getWorkbook(new File("path/to/your/file.xls"));
WritableWorkbook writableWorkbook = Workbook.createWorkbook(new File("path/to/your/updated/file.xls"), workbook);

// Get the desired sheet
WritableSheet sheet = writableWorkbook.getSheet(0);

// Get the cell and create a new note
WritableCell cell = sheet.getWritableCell(colNum, rowNum);
WritableCellFeatures cellFeatures = new WritableCellFeatures();
cellFeatures.setComment("This is a note.");
cell.setCellFeatures(cellFeatures);

// Save the changes to the Excel file
writableWorkbook.write();
writableWorkbook.close();

// Close the workbook
workbook.close();

這程式一看就知道不是我寫的
是問ChatGPT寫的

u9934001 iT邦新手 5 級 ‧ 2023-06-09 12:11:20 檢舉

好的,我試試
ChatGPT真是萬能XD

我要發表回答

立即登入回答