I am trying to read an Excel file from Revit 2017 API, using Revit Python Shell. Basically, I have no idea of what I'm doing, but I tried this: http://wiki.theprovingground.org/revit-api-py-excel , but I'm getting an error:
Traceback (most recent call last):
File "", line 1, in
EnvironmentError: System.Runtime.InteropServices.COMException (0x800401F3): Invalid class string (Exception from HRESULT: 0x800401F3 (CO
at System.Runtime.InteropServices.Marshal.CLSIDFromProgID(String progId, Guid& clsid)
at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.b__0()
when running:
System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')
I am doing this on a Windows 7 machine.
On side of that, I tried pretty much every module I found on the web, that are supposed to help opening xlsx files, but every time I'm getting and error at some point. Can anybody help on that? It can be ods files as well.
Thanks!
Arnaud.
The code you're using (System.Runtime.InteropServices.Marshal.GetActiveObject('Excel.Application')) assumes Excel is already running.
Check this page for a different approach: http://www.ironpython.info/index.php?title=Interacting_with_Excel
Basically, try this:
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
import Microsoft.Office.Interop.Excel as Excel
excel = Excel.ApplicationClass()
If you want to get an active instance (if any), you could use your first method in a try/except block and only create a new excel instance if none is found.
Another option is to use module xlrd - this way you won't need to have Excel installed. This question discusses some issues with using xlrd in IronPython
Why use a proprietary file format like XLS instead of something sensible, simple and open like CSV?
https://en.wikipedia.org/wiki/Comma-separated_values
Related
How can I save data in an R compressed file format and then open it in Excel Power Query? I've opened in PowerBI Power Query no problem by setting the R path and using R.Execute(), but Power Query in Excel only has an RData.FromBinary() function.
Hopefully it can be loaded into Excel without any external dependencies as I'd like to switch from accdb files on a shared drive for the purpose of sharing easily refreshable data sets.
I tried exporting with these 3 methods:
saveRDS(tmp, "c:/users/ian/Documents/CRAN_mirrors.rds")
save(tmp, file="c:/users/ian/Documents/CRAN_mirrors.RData")
save.image(file="c:/users/ian/Documents/CRAN_mirrors.RData")
And tried importing with both:
= RData.FromBinary(File.Contents("C:\Users\ian\Documents\CRAN_mirrors.rds"))
and
= RData.FromBinary(File.Contents("C:\Users\ian\Documents\CRAN_mirrors.RData"))
Either of those import attempts gives me the following error:
DataFormat.Error: Exception of type 'Microsoft.Analytics.Modules.R.ErrorHandling.RException.Primitives.NotValidRDataException' was thrown.
Been using R for around two years now and this is the first time i've encountered this issue. I have a data.frame with approx 31,000 rows and 400 cols and I want to export to an excel sheet using write_xlsx
When I try this I get the following error:
write_xlsx(data, "FILEPATH")
[ERROR][libxlsxwriter/packager.c:1142]: Error in writing member in the zipfile
[ERROR] workbook_close(): Zip ZIP_ERRNO error while creating xlsx file 'FILEPATH'. System error = No error
Error: Error in libxlsxwriter: 'Zip generic error ZIP_ERRNO while creating the xlsx file.'
I think this error started when I inadvertently tried to open an Excel file that R was writing before it had actually completed. I have shut down R and restarted and also re-installed the writexl package to no avail.
The data i'm attempting to export is approx 150mb. When I try to write a smaller file (1.5mb) this works but when I try to open the excel file it says it is locked for editing by R and can open be opened 'read only'.
I have exported much larger data than this in the past with no issues so cannot figure this out, any help appreciated.
What OS are you using and is it possible that you are running out of free space in the tmp directory? – jmcnamara yesterday
I think you've cracked it. I had returned to work on Monday, ran the script again and, sure enough, it worked first time. Only difference is I had deleted some content from the directory I was working in because I had got a disk full notice!
I don't know write_xlsx but I would suggest a simple alternative as the following:
library(rio)
library(xlsx)
export(data, "exportname.xlsx")
However in your code might you need to add the file name as the following:
library(writexl)
write_xlsx(data, "FILEPATH// file name.xlsx")
Might this source could be helpful: https://datatofish.com/export-dataframe-to-excel-in-r/
I'm trying to load an Excel workbook with a large number of tabs into R, do some analysis, and then export the results back into Excel. I'm using the openxlsx package because of some of the features of that package that are not easily accessible using other packages (such as the ability to create "comments" in the output file, color code the tabs, and work with 64-bit R).
When I try to read in the workbooks, I sometimes get the following error message (or something similar):
Error in unzip(xlsxFile, exdir = xmlDir) :
cannot open file 'C:/Users/MENDEL~1/AppData/Local/Temp/RtmpIb3WOf/_excelXMLRead/xl/worksheets/sheet5.xml': Permission denied
This error message doesn't always show up - but sometimes it will appear and the program crashes.
Does anyone have any ideas how to fix this problem? I don't know why the program sometimes thinks it doesn't have permission to access the sheets.
Thank you in advance!
I can think of two possible scenarios for this error:
Scenario 1:
C:/Users/MENDEL~1/AppData/Local/ (This looks like you are trying to read a temporary file)
Solution:
If that is the case try moving the file to a different location like desktop and make sure that you update your working directory accordingly.
Scenario 2
C:/Users/MENDEL~1/AppData/Local/Temp/RtmpIb3WOf/_excelXMLRead/xl/worksheets/sheet5.xml' (Looks like there is some issue with Sheet5 which is of type .xml and the openxlsx does not allow you to read .xml)
Solution:
Check if there is some issue with the format or contents of sheet5 in the file that you are trying to read.
For additional information check CRAN Documentation
I am sorry about posting a not reproducible error but the task is with huge and not splittable files (.RData ones to be precise).
There are several similar questions, like this one or this other one but they all are made for importing .csv files which is not my case.
As title, I am trying to load with the load function an .RData files but this triggers this error:
load("trip.Rdata")
Error: embedded nul in string: ''<div id=BOD,socationid="7278708">\0\004\0\t\0\0\0\037<span ->\0\004\0\t\0\0\0.<div id="MAINWRAP" c'
I've also tried with attach that, by documentation, is able to handle .RData files but the error is always the same.
Now, this is awkward because and .RData file is the last one from which I would expect an error triggered.
To be honest I do not even know how to ask this question properly because of its awkwardness (I can understand the downvote).
Maybe a solution might rely on the fact that the file is been saved under windows OS and I'm trying to load it on a Mac OS but I can't figure out a way, a possible cause nor a possible solution.
Any help is appreciated.
I am attempting to create a script which will distribute a number of pdfs into a folder tree according to tags. I have the file metadata (including filepath) in a bibtex format. I have tried a number of work-arounds to import the metadata, but so far have been unable to get the filepath, year, title, and tags into a single data frame.
When I try to import using read.bib (which seems the simplest solution) I get the following error:
dbase_full <- read.bib("C:/Users/WILIAM-PLAN/Desktop/My Collection 23 07.bib")
Error in read.bib("C:/Users/WILIAM-PLAN/Desktop/My Collection 23 07.bib") :
lex fatal error:
fatal flex scanner internal error--end of buffer missed
I have looked up the error but language of the 'under the hood' part of the {bibtex} package (lex scanners etc) is beyond me.
Is there quick fix for this error?
If not, is there another way to get the file metadata from bibtex into a dataframe?
i had the same problem.
The problem is that in the bib file could be in some fields (as abstract) lines with a lot of chars..
You need to split and wrap them.
I hope it is useful