开创了Apache的POI使用HSSFClientAnchor单元格批注 [英] creating cell comments using HSSFClientAnchor in apache poi
问题描述
可能有人请向我解释如何创建单元格批注时正确使用锚?雷人的工作,但S $ P $垫板材改变,我有让我的单元格批注出现的问题。这是code,我使用的工作:
注释C = drawing.createCellComment(新HSSFClientAnchor(0,0,0,0,(短)4,2,(短)6,5));
这是通过试验发现身边居多。综观API它不完全让它更清楚。
根据快速入门指南我自己也尝试没有运气以下内容:
ClientAnchor锚= chf.createClientAnchor();
注释C = drawing.createCellComment(锚);
c.setString(chf.createRichTextString(消息));
一个有点晚了,但是这可能会工作(它为我工作,而从快速启动Apache POI例子也并没有为我工作):
公共无效setComment(字符串文本,细胞单元){
最终地图<表,HSSFPatriarch> drawingPatriarches =新的HashMap<表,HSSFPatriarch>(); 。CreationHelper createHelper = cell.getSheet()getWorkbook()getCreationHelper();
HSSFSheet表=(HSSFSheet)cell.getSheet();
HSSFPatriarch drawingPatriarch = drawingPatriarches.get(片);
如果(drawingPatriarch == NULL){
drawingPatriarch = sheet.createDrawingPatriarch();
drawingPatriarches.put(片材,drawingPatriarch);
} 注释评论= drawingPatriarch.createComment(新HSSFClientAnchor(0,0,0,0,(短)4,2,(短)6,5));
comment.setString(createHelper.createRichTextString(文本));
cell.setCellComment(注解);
}
埃里克Pragt
Could someone please explain to me how to properly use the Anchors when creating cell comments? Mine were working, but the spread sheet changed and I am having issues getting my cell comments to appear. This is the code I was using that worked:
Comment c = drawing.createCellComment (new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5));
That was found mostly by experimenting around. Looking at the api for it doesn't exactly make it any clearer.
Based on the quick start guide I have also tried the following with no luck:
ClientAnchor anchor = chf.createClientAnchor();
Comment c = drawing.createCellComment(anchor);
c.setString(chf.createRichTextString(message));
A bit late, but this will probably work (it works for me, while the Apache POI example from the quick start also didn't work for me):
public void setComment(String text, Cell cell) {
final Map<Sheet, HSSFPatriarch> drawingPatriarches = new HashMap<Sheet, HSSFPatriarch>();
CreationHelper createHelper = cell.getSheet().getWorkbook().getCreationHelper();
HSSFSheet sheet = (HSSFSheet) cell.getSheet();
HSSFPatriarch drawingPatriarch = drawingPatriarches.get(sheet);
if (drawingPatriarch == null) {
drawingPatriarch = sheet.createDrawingPatriarch();
drawingPatriarches.put(sheet, drawingPatriarch);
}
Comment comment = drawingPatriarch.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
comment.setString(createHelper.createRichTextString(text));
cell.setCellComment(comment);
}
Erik Pragt
这篇关于开创了Apache的POI使用HSSFClientAnchor单元格批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!