Excel 带有 xlsx 包的鼠标悬停文本
Excel mouse hover text with xlsx package
有没有办法编写鼠标悬停文本,如下所示:"look at 7:35 min"
我在 R 中使用 xlsx 包。
它不必像视频中那样看起来很花哨。当我将鼠标悬停在“???”上时,我只想显示一些文本细胞.
有什么建议吗?
让你们开始:
library(xlsx)
write.xlsx("???",file="hoverText.xlsx",row.names = F,col.names = F)
wb <- loadWorkbook("hoverText.xlsx")
sheet <- getSheets(wb)
编辑:
添加评论(类似于悬停文本),但对于我打算写的文本,评论框太小了。 (在Excel我可以手动更改大小,让我们尝试找到一种R方法来更改评论框大小)
library(xlsx)
write.xlsx("???",file="hoverText.xlsx",row.names = F,col.names = F)
wb <- loadWorkbook("hoverText.xlsx")
sheet <- getSheets(wb)[[1]]
row <- xlsx::getRows(sheet)
cell <- xlsx::getCells(row, colIndex = 1)
comment <- "most foobar comment of all time\nhopefully with newline"
createCellComment(cell[[1]], string=comment, author=NULL, visible=TRUE)
saveWorkbook(wb,file="hoverText.xlsx")
编辑 2:
经过几个小时的网络搜索仍然没有成功。它与那些功能有关:
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(cell.getRowIndex()); anchor.setRow2(cell.getRowIndex()+ 1);
anchor.setDx1(100);
anchor.setDx2(100);
anchor.setDy1(100);
anchor.setDy2(100);
评论框自动调整大小有vba解决方案
CELL.Comment.Shape.TextFrame.AutoSize = True
还不知道如何 运行 VBA 在 excel 中从 R
编码
- 从第一次编辑中获取代码:
- 将 createCellComment 更改为 createCellComment2 或覆盖函数
- 这主要是评论框的xlsx::createCellComment和
height
和width
createCellComment2 <- function (cell, string, author = NULL, visible = TRUE,height=2,width=2) {
sheet <- .jcall(cell, "Lorg/apache/poi/ss/usermodel/Sheet;", "getSheet")
wb <- .jcall(sheet, "Lorg/apache/poi/ss/usermodel/Workbook;", "getWorkbook")
factory <- .jcall(wb, "Lorg/apache/poi/ss/usermodel/CreationHelper;", "getCreationHelper")
anchor <- .jcall(factory, "Lorg/apache/poi/ss/usermodel/ClientAnchor;", "createClientAnchor")
.jcall(anchor, "V", "setCol2", as.integer(width))
.jcall(anchor, "V", "setRow2", as.integer(height))
drawing <- .jcall(sheet, "Lorg/apache/poi/ss/usermodel/Drawing;", "createDrawingPatriarch")
comment <- .jcall(drawing, "Lorg/apache/poi/ss/usermodel/Comment;", "createCellComment", anchor)
rtstring <- factory$createRichTextString(string)
comment$setString(rtstring)
if (!is.null(author))
.jcall(comment, "V", "setAuthor", author)
if (visible)
.jcall(cell, "V", "setCellComment", comment)
invisible(comment)
}
有没有办法编写鼠标悬停文本,如下所示:"look at 7:35 min"
我在 R 中使用 xlsx 包。
它不必像视频中那样看起来很花哨。当我将鼠标悬停在“???”上时,我只想显示一些文本细胞.
有什么建议吗?
让你们开始:
library(xlsx)
write.xlsx("???",file="hoverText.xlsx",row.names = F,col.names = F)
wb <- loadWorkbook("hoverText.xlsx")
sheet <- getSheets(wb)
编辑:
添加评论(类似于悬停文本),但对于我打算写的文本,评论框太小了。 (在Excel我可以手动更改大小,让我们尝试找到一种R方法来更改评论框大小)
library(xlsx)
write.xlsx("???",file="hoverText.xlsx",row.names = F,col.names = F)
wb <- loadWorkbook("hoverText.xlsx")
sheet <- getSheets(wb)[[1]]
row <- xlsx::getRows(sheet)
cell <- xlsx::getCells(row, colIndex = 1)
comment <- "most foobar comment of all time\nhopefully with newline"
createCellComment(cell[[1]], string=comment, author=NULL, visible=TRUE)
saveWorkbook(wb,file="hoverText.xlsx")
编辑 2:
经过几个小时的网络搜索仍然没有成功。它与那些功能有关:
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(cell.getRowIndex()); anchor.setRow2(cell.getRowIndex()+ 1);
anchor.setDx1(100);
anchor.setDx2(100);
anchor.setDy1(100);
anchor.setDy2(100);
评论框自动调整大小有vba解决方案
CELL.Comment.Shape.TextFrame.AutoSize = True
还不知道如何 运行 VBA 在 excel 中从 R
编码- 从第一次编辑中获取代码:
- 将 createCellComment 更改为 createCellComment2 或覆盖函数
- 这主要是评论框的xlsx::createCellComment和
height
和width
createCellComment2 <- function (cell, string, author = NULL, visible = TRUE,height=2,width=2) { sheet <- .jcall(cell, "Lorg/apache/poi/ss/usermodel/Sheet;", "getSheet") wb <- .jcall(sheet, "Lorg/apache/poi/ss/usermodel/Workbook;", "getWorkbook") factory <- .jcall(wb, "Lorg/apache/poi/ss/usermodel/CreationHelper;", "getCreationHelper") anchor <- .jcall(factory, "Lorg/apache/poi/ss/usermodel/ClientAnchor;", "createClientAnchor") .jcall(anchor, "V", "setCol2", as.integer(width)) .jcall(anchor, "V", "setRow2", as.integer(height)) drawing <- .jcall(sheet, "Lorg/apache/poi/ss/usermodel/Drawing;", "createDrawingPatriarch") comment <- .jcall(drawing, "Lorg/apache/poi/ss/usermodel/Comment;", "createCellComment", anchor) rtstring <- factory$createRichTextString(string) comment$setString(rtstring) if (!is.null(author)) .jcall(comment, "V", "setAuthor", author) if (visible) .jcall(cell, "V", "setCellComment", comment) invisible(comment) }