2017-03-27 7 views
1

有沒有辦法將程序鼠標懸停文字是這樣的:使用"look at 7:35 min"Excel的鼠標懸停文字與XLSX包

IM的XLSX包河

它沒有看任何幻想像在視頻中。我只是想讓一些文字出現在我懸停在「???」細胞。

有什麼建議嗎?

爲了讓你們開始:

library(xlsx) 

write.xlsx("???",file="hoverText.xlsx",row.names = F,col.names = F) 

wb <- loadWorkbook("hoverText.xlsx") 
sheet <- getSheets(wb) 

編輯:

添加評論(有點像懸停文本),但評論框的方式向小型化,文本我意圖寫。 (在Excel中我可以手動更改尺寸,讓我們試着找出A 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") 

EDIT2:

在網上搜索仍然沒有成功的小時後。它是與這些功能:

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); 

沒有爲評論框自動調整大小

CELL.Comment.Shape.TextFrame.AutoSize = True 

不知道還如何在Excel中自R

回答

0
    運行VBA代碼VBA解決方案
  1. 從第1行獲取代碼編輯:
  2. 將createCellComment更改爲createCellComment2或覆蓋函數
  3. 這多爲XLSX :: createCellComment與height和評論框
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) 
} 
width