我正在尝试使用Apache poi XSSFWorkbook在.xlsm excel模板中添加注释,但是注释始终显示透明的背景色。有人知道如何操纵XSSFWorkbook的注释样式吗? Apache poi:v3.15; excel扩展名:.xlsm; 操作系统:Mac
这就是我发现的内容:当前的模板样式可能会影响XSSFWorkbook的注释样式,因为在创建全新的工作表或模板时,添加注释的效果很好。...但是我确实需要在所需的现有工作表中添加注释。
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType
import org.apache.poi.ss.usermodel._
import org.apache.poi.ss.util.{CellRangeAddress, CellReference}
import org.apache.poi.util.Units
import org.apache.poi.xssf.usermodel._
val file = WorkbookFactory.create("worksheet.xlsm")
private def setComment(file: Workbook) : Workbook = {
//get sheet
val currentSheet = file.getSheet("Sheet1")
val rowInfo = currentSheet.getRow(2)
val cell = rowInfo.getCell(3)
//begin adding comment
val factory = file.getCreationHelper()
val drawing = cell.getSheet.createDrawingPatriarch()
//create comment box
val anchor = factory.createClientAnchor()
//locate comment
anchor.setCol1(cell.getColumnIndex + 1 )
anchor.setRow1(cell.getRowIndex+1)
anchor.setCol2(cell.getColumnIndex + 5 )
anchor.setRow2(cell.getRowIndex + 4)
val comment1 = drawing.createCellComment(anchor)
val str = factory.createRichTextString("this is a comment")
comment1.setString(str)
cell.setCellComment(comment1)
file
}
将鼠标悬停在不透明的背景注释上时,预期结果应该是正常的黄框注释