openpyxl validation error schemas.openxmlformats.org/spreadsheetml/2006/main:color - openpyxl

I used openpyxl to create an Excel workbook.
When validating the the workbook, I get the validation error:
"The element has unexpected child element http://schemas.openxmlformats.org/spreadsheetml/2006/main:color""
The same workbook opened by Excel gives this:
We found a problem with some content in copy_book1_excel2019.xlsx. Do you want us to try to recover as much as we can?
Steps to reproduce
(openpyxl 3.0.3, python 3.6.9, Excel 2019 (Pro), Validation with "Open XML SDK 2.5 Productivty tool (Microsoft)
1) Create an empty workbook in excel 2019 (Pro version) and save it as "book1_excel2019.xlsx"
2) Python code:
import openpyxl
wb = openpyxl.load_workbook('./book1_excel2019.xlsx')
wb.save("copy_book1_excel2019.xlsx")
3) Validation:
book1_excel2019.xlsx -> ok
copy_book1_excel2019.xlsx -> 1 validation error:
"The element has unexpected child element "http://schemas.openxmlformats.org/spreadsheetml/2006/main:color"
Any hints where to look?

Related

Python script to run vba Error msg

I've posted the same question here
pyvot: can I run Excel VBA macros from python script?
I'm new to Python, so I do alot of searching.
Trying to Run a VBA project using snippets of Python code
Have encountered this error message, Win 7 based error I think.
Error message from PyScriptor reads as:
com_error:(-2147352567,'Exception occured',(0,"Microsoft \excel',
Excel cannot access 'MYFOLDERNAME,, The document may be read-only or
encrypted,", 'xlmain11.chm.,0,-2146827284),none)
Sorry about the forum errors, thought it was being helpfull, as I'm not taking the credit for this actual peiece of code.
import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename="C:\MYFOLDERNAME",ReadOnly=0)
xl.Application.Run("py_counter_test")
xl.Workbooks(1).Close(SaveChanges=1)
xl.Application.Quit()
xl=0
This the error I get, believe it's Win 7 issue.
I know I have not encrypted the folder, it is simply a "New Folder" in C:\
com_error:(-2147352567,'Exception occured',(0,"Microsoft \excel', Excel cannot access 'MYFOLDERNAME,, The document may be read-only or encrypted,", 'xlmain11.chm.,0,-2146827284),none)
Thanks
I saw the error,( over-sight ) left out the workbook name.
Amended code error.
import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename="C:\MYFOLDERNAME\PY-COUNTER.xlsm",ReadOnly=0)
xl.Application.Run("Macro1")

VBA Excel 2010 FormatConditions failing Application Defined or Object Defined Error

I have a VBA code that I used to use in an Excel 2016 (64-bit), and it works fine.
But when I tried to use in a Excel 2010 (32-bit) version, I've got an error "Runtime Error (1004) Application Defined or Object Defined Error" in the following line:
CndFrmtType = Sh.Cells.FormatConditions(CndFrmtItem).Type
I've already tried to re-build the file in a 2010 Excel (from the ground, to avoid reference's issues), but it still not working.
I really tried to google it, but didn't find anything about an eventual incompatibility in the FormatConditions object.
The returned FormatConditions object is as follows:
Can anyone help me on this?
be sure you have:
set Sh to a valid Worksheet object
initialized CndFrmtItem to a valid name or index number to reference a format condition of that worksheet
declared CndFrmtType as of Long type
and it'll work

DataTable.ImportSheet operation failed.Invalid file

I'm running Excel tests on UFT and sometimes I get the error number 20012 which is "DataTable.ImportSheet operation failed.Invalid file".
This is my way of importing the script:
DataTable.ImportSheet filepath,scriptname,"Action2"
filepath is the path of my workbook which conatins many excel sheets (scripts)
scriptname: the name of the script that I want to run
Action2: contains all the call of all possible keywords that may script can contains.
Any help please, why I'm getting this error.
The problem is that this is working well for some scripts and for others not after 3 or 4 run times.
I think the problem is on Excel itself and not on the code, are there any problems when working with Excel 2016 and UFT 12 ?
UFT syntax for importing a worksheet is:
DataTable.ImportSheet FileName, vtSrcSheet, vtDstSheet
This means you need to pass as parameters the filename (and path) to the excel file, the name (or index) of the source sheet you want to import, and then the destination you want this sheet to be (for example "Global" or "Action1" etc)
Unless scriptname happens to be the exact name of the worksheet you are trying to import you will get this error.
If you want to import the whole file use Datatable.Import instead of Datatable.ImportSheet

.NET How to open CSV with Excel Interop without text converted to formulas

I'm currently presented with the following issue:
I need to open a CSV file with the Excel Interop Classes (15.0). This is done using the following code:
Dim app As New Excel.Application
Dim workbook As Excel.Workbook = app.Workbooks.Open(sFileNameCSV, Format:=4, Local:=True)
Unfortunately this converts some of the data into formulas (e.g. text starting with a hyphen [- this is an example] or phone numbers in international format [+41-555-123-45-67]) resulting in either a #NAME? error or a calculated result in case of the phone number.
After some searching in the web and on SO I tried the following things with no luck:
Saving the CSV File as a .txt file
Using the OpenText() Method instead of the Open() method
Combination of the two above
Is there any solution to this issue without having to change the CSV file data itself and still using the Interop classes, like disabling formulas altogether? Or am I just missing a param in the Open() / OpenText() functions?

Error importing and exporting excel data to vb.net, "Microsoft.Office.Interop.Excel.Application is not defined"

I am trying to run a file I downloaded to import and export data from excel.
I downloaded from from the following site:
http://www.sattsoft.com/sourcecodes/details/1/9/import-export-data-to-excel-using-vb-net.html
When I run the file the error comes on the following lines
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
These are the errors that come on those respective lines
Type "Microsoft.Office.Interop.Excel.Application is not defined"
Type "Microsoft.Office.Interop.Excel.Workbook is not defined"
Type "Microsoft.Office.Interop.Excel.Worksheet is not defined"
What I want to do is to run the file without the errors so that I can import and export data from excel to vb.net datagridview.
I am using Excel 2010 and visual studio 2010
How do I get around this error so I can run the file?
Add COM reference Microsoft.Office.Interop.Excel to your project, it's called Microsoft Excel XX.Y Object Library (XX.Y is version number depending of installed Excel).
I had to use this library in references from the "Extensions" section (not not under COM); had to select Microsoft.Office.Interop.Excel, version 15.0.0.0.
That fixed the error.
Selecting the COM reference did not resolve this message.