gpt4 book ai didi

java - 从 CellComment 检索 ClientAnchor 时的 POI 3.17 NPE

转载 作者:行者123 更新时间:2023-12-02 10:58:06 24 4
gpt4 key购买 nike

尝试将 CellComments 从同一工作簿中的一张工作表复制到另一张工作表时,检索 CellComment ClientAnchor 会收到 NPE。

java.lang.NullPointerException at org.apache.poi.xssf.usermodel.XSSFComment.getClientAnchor(XSSFComment.java:220)

使用的代码:

for (Entry<CellAddress, ? extends Comment> e : sheet.getCellComments().entrySet())
{
CellAddress addr = e.getKey();
Comment comment = e.getValue();
ClientAnchor anchor = comment.getClientAnchor();

这是POI的问题还是检索码的问题?

请注意,以下代码有效并检索 ClientAnchor。

  for (CellAddress addr : sheet.getCellComments().keySet())
{
Comment comment = sheet.getCellComment(addr);
ClientAnchor anchor = comment.getClientAnchor();

最佳答案

这绝对是apache poi的问题,至少有apache poi版本3.17 。这类问题是我没有加入 apache poi 的原因之一的开发者列表。

以下所有内容都是关于apache poi版本3.17 .

如果XSSFComment.java:220抛出 NPE,然后 _vmlShapenull 。那么什么是_vmlShape ?这是一个com.microsoft.schemas.vml.CTShape通常设置为 XSSFComment的构造函数。

public XSSFComment(CommentsTable comments, CTComment comment, CTShape vmlShape) .

那么为什么会是 null值为 EntryXSSFSheet.getCellComments().entrySet()

XSSFSheet public Map getCellComments()返回sheetComments.getCellComments() 。那么什么是sheetComments ?这是一个org.apache.poi.xssf.model.CommentsTable这是在 reading the sheet's package part from the worbook 时阅读的.

返回的是什么sheetComments.getCellComments() ?它返回 final TreeMap<CellAddress, XSSFComment> map 其中每个值都是 XSSFComment 。但所有这些XSSFComment是新建的,具有 CTShape vmlShape =null :map.put(e.getKey(), new XSSFComment(this, e.getValue(), null)); .

嗯,这就是为什么 _vmlShapenullXSSFComment.java代码行 220 抛出了 NPE。

为什么sheet.getCellComment(addr)作品有 addr一个CellAddress得到相同的 key TreeMap<CellAddress, XSSFComment>

因为程序员已经知道 VMLDrawing 的必要性,参见 public XSSFComment getCellComment(CellAddress address)

关于java - 从 CellComment 检索 ClientAnchor 时的 POI 3.17 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51560755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com