我正在编写Excel AddIn,并且Range.Autofilter方法存在问题。
对我不起作用的最小代码示例:
library(text2vec)
#with your docuemnts...
#texts = c(document1, document2, document3)
#create iterator to split texts into tokens
iterator <- itoken(texts,
preprocessor = tolower,
tokenizer = word_tokenizer,
progressbar = FALSE)
#create the vocabulary of tokens
vocabulary <- create_vocabulary(iterator)
#combine tokens into a document term matrix
#this will be a sparse matrix (see the package "Matrix" for details)
#you might need to convert your dtm objects with as.matrix() to "normal" matrices
#depending on your downstream task (although most packages accept sparse matrices)
#note, that when converting with as.matrix(), you will loose the memory of advantage of sparse matrices
dtm <- create_dtm(iterator, vocab_vectorizer(vocabulary))
str(dtm)
# Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
# ..@ i : int [1:192] 1 2 2 0 2 2 0 1 2 0 ...
# ..@ p : int [1:173] 0 1 2 3 4 5 6 7 8 9 ...
# ..@ Dim : int [1:2] 3 172
# ..@ Dimnames:List of 2
# .. ..$ : chr [1:3] "1" "2" "3"
# .. ..$ : chr [1:172] "recognised" "premium" "finest" "william" ...
# ..@ x : num [1:192] 1 1 1 1 1 1 1 1 1 1 ...
# ..@ factors : list()
#set up basic tfidf model
tfidf <- TfIdf$new()
#apply model to your dtm
dtm_tfidf <- fit_transform(dtm, tfidf)
str(dtm_tfidf)
# Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
# ..@ i : int [1:192] 1 2 2 0 2 2 0 1 2 0 ...
# ..@ p : int [1:173] 0 1 2 3 4 5 6 7 8 9 ...
# ..@ Dim : int [1:2] 3 172
# ..@ Dimnames:List of 2
# .. ..$ : chr [1:3] "1" "2" "3"
# .. ..$ : chr [1:172] "recognised" "premium" "finest" "william" ...
# ..@ x : num [1:192] 0.01126 0.00461 0.00461 0.00322 0.00461 ...
# ..@ factors : list()
此代码为我抛出错误800A03EC。 我正在使用Excel 2013和Visual Studio 2012,如果这会影响答案。
答案 0 :(得分:0)
就我而言,问题是如果数据被格式化为表(或者在代码中是ListObject),Range.AutoFilter()似乎不起作用。相反,我通过
得到了预期的结果foreach (ListObject obj in currentWorksheet.ListObjects)
{
obj.ShowAutoFilter = true;
}