Excel file is being corrupted when trying to modify 1 cell using openpyxl python.
I am trying to change 1 cell in a macro enabled excel 2013 file using openpyxl. This should be a relatively easy task I have the following code it works but for some reason when I later try to open the modified excel file I get the error message from excel.
" We found a problem with some contents in "workbook" do you want to recover?"
if I recover the file it removes a lot of content from the file but I can still see that the only cell I wanted to modify has the correct data.
when I open the error log I get the following message:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error086600_01.xml</logFileName>
<summary>Errors were detected in file 'C:Files2018 WorkflowStress Due Date (NA) --- TR9999999 Pckg#9 - Emergency Equipment - 9 - 9 - 9Panel Analysis --- 9 Version A.xlsm'</summary>
-<repairedParts summary="Following is a list of repairs:">
<repairedPart xml:space="preserve">Repaired Part: /xl/worksheets/sheet1.xml part. </repairedPart>
</repairedParts>
</recoveryLog>
The following is my python code, I have looked through the documentation and it seems like it should be working but why is it corrupting my files?
"""
The next part of the script will modify the stress panel excel documents
"""
wb = load_workbook(filename = os.path.join(new_path,new_panel + excel_ext), read_only = False, keep_vba = True)
ws = wb.get_sheet_by_name("Adapter_Panel_Tool")
ws['C2'] = "Adapter Panel Quick Stress Analyses Tool - " + packet_list['Installations list'][0]
wb.save(os.path.join(new_path,new_panel + " Version A" + excel_ext))
wb.close()
#checks if there are 2 files: the filled one and the empty one and deletes the empty if it exist.
is_file_filled_out = os.path.isfile(os.path.join(new_path,new_panel + " Version A" + excel_ext))
is_there_empty_file = os.path.isfile(os.path.join(new_path, new_panel + excel_ext))
if is_file_filled_out == True and is_there_empty_file == True:
os.remove(os.path.join(new_path,new_panel + excel_ext))
print("nn The following file will be remove: n" + new_panel + excel_ext + "nn" )
print("The prefilled template has been created: n " + new_path + new_panel + excel_ext)
python excel vba python-3.x excel-vba
add a comment |
I am trying to change 1 cell in a macro enabled excel 2013 file using openpyxl. This should be a relatively easy task I have the following code it works but for some reason when I later try to open the modified excel file I get the error message from excel.
" We found a problem with some contents in "workbook" do you want to recover?"
if I recover the file it removes a lot of content from the file but I can still see that the only cell I wanted to modify has the correct data.
when I open the error log I get the following message:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error086600_01.xml</logFileName>
<summary>Errors were detected in file 'C:Files2018 WorkflowStress Due Date (NA) --- TR9999999 Pckg#9 - Emergency Equipment - 9 - 9 - 9Panel Analysis --- 9 Version A.xlsm'</summary>
-<repairedParts summary="Following is a list of repairs:">
<repairedPart xml:space="preserve">Repaired Part: /xl/worksheets/sheet1.xml part. </repairedPart>
</repairedParts>
</recoveryLog>
The following is my python code, I have looked through the documentation and it seems like it should be working but why is it corrupting my files?
"""
The next part of the script will modify the stress panel excel documents
"""
wb = load_workbook(filename = os.path.join(new_path,new_panel + excel_ext), read_only = False, keep_vba = True)
ws = wb.get_sheet_by_name("Adapter_Panel_Tool")
ws['C2'] = "Adapter Panel Quick Stress Analyses Tool - " + packet_list['Installations list'][0]
wb.save(os.path.join(new_path,new_panel + " Version A" + excel_ext))
wb.close()
#checks if there are 2 files: the filled one and the empty one and deletes the empty if it exist.
is_file_filled_out = os.path.isfile(os.path.join(new_path,new_panel + " Version A" + excel_ext))
is_there_empty_file = os.path.isfile(os.path.join(new_path, new_panel + excel_ext))
if is_file_filled_out == True and is_there_empty_file == True:
os.remove(os.path.join(new_path,new_panel + excel_ext))
print("nn The following file will be remove: n" + new_panel + excel_ext + "nn" )
print("The prefilled template has been created: n " + new_path + new_panel + excel_ext)
python excel vba python-3.x excel-vba
Edit your Question and show the value of+ excel_ext
.
– stovfl
Nov 15 '18 at 19:32
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01
add a comment |
I am trying to change 1 cell in a macro enabled excel 2013 file using openpyxl. This should be a relatively easy task I have the following code it works but for some reason when I later try to open the modified excel file I get the error message from excel.
" We found a problem with some contents in "workbook" do you want to recover?"
if I recover the file it removes a lot of content from the file but I can still see that the only cell I wanted to modify has the correct data.
when I open the error log I get the following message:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error086600_01.xml</logFileName>
<summary>Errors were detected in file 'C:Files2018 WorkflowStress Due Date (NA) --- TR9999999 Pckg#9 - Emergency Equipment - 9 - 9 - 9Panel Analysis --- 9 Version A.xlsm'</summary>
-<repairedParts summary="Following is a list of repairs:">
<repairedPart xml:space="preserve">Repaired Part: /xl/worksheets/sheet1.xml part. </repairedPart>
</repairedParts>
</recoveryLog>
The following is my python code, I have looked through the documentation and it seems like it should be working but why is it corrupting my files?
"""
The next part of the script will modify the stress panel excel documents
"""
wb = load_workbook(filename = os.path.join(new_path,new_panel + excel_ext), read_only = False, keep_vba = True)
ws = wb.get_sheet_by_name("Adapter_Panel_Tool")
ws['C2'] = "Adapter Panel Quick Stress Analyses Tool - " + packet_list['Installations list'][0]
wb.save(os.path.join(new_path,new_panel + " Version A" + excel_ext))
wb.close()
#checks if there are 2 files: the filled one and the empty one and deletes the empty if it exist.
is_file_filled_out = os.path.isfile(os.path.join(new_path,new_panel + " Version A" + excel_ext))
is_there_empty_file = os.path.isfile(os.path.join(new_path, new_panel + excel_ext))
if is_file_filled_out == True and is_there_empty_file == True:
os.remove(os.path.join(new_path,new_panel + excel_ext))
print("nn The following file will be remove: n" + new_panel + excel_ext + "nn" )
print("The prefilled template has been created: n " + new_path + new_panel + excel_ext)
python excel vba python-3.x excel-vba
I am trying to change 1 cell in a macro enabled excel 2013 file using openpyxl. This should be a relatively easy task I have the following code it works but for some reason when I later try to open the modified excel file I get the error message from excel.
" We found a problem with some contents in "workbook" do you want to recover?"
if I recover the file it removes a lot of content from the file but I can still see that the only cell I wanted to modify has the correct data.
when I open the error log I get the following message:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error086600_01.xml</logFileName>
<summary>Errors were detected in file 'C:Files2018 WorkflowStress Due Date (NA) --- TR9999999 Pckg#9 - Emergency Equipment - 9 - 9 - 9Panel Analysis --- 9 Version A.xlsm'</summary>
-<repairedParts summary="Following is a list of repairs:">
<repairedPart xml:space="preserve">Repaired Part: /xl/worksheets/sheet1.xml part. </repairedPart>
</repairedParts>
</recoveryLog>
The following is my python code, I have looked through the documentation and it seems like it should be working but why is it corrupting my files?
"""
The next part of the script will modify the stress panel excel documents
"""
wb = load_workbook(filename = os.path.join(new_path,new_panel + excel_ext), read_only = False, keep_vba = True)
ws = wb.get_sheet_by_name("Adapter_Panel_Tool")
ws['C2'] = "Adapter Panel Quick Stress Analyses Tool - " + packet_list['Installations list'][0]
wb.save(os.path.join(new_path,new_panel + " Version A" + excel_ext))
wb.close()
#checks if there are 2 files: the filled one and the empty one and deletes the empty if it exist.
is_file_filled_out = os.path.isfile(os.path.join(new_path,new_panel + " Version A" + excel_ext))
is_there_empty_file = os.path.isfile(os.path.join(new_path, new_panel + excel_ext))
if is_file_filled_out == True and is_there_empty_file == True:
os.remove(os.path.join(new_path,new_panel + excel_ext))
print("nn The following file will be remove: n" + new_panel + excel_ext + "nn" )
print("The prefilled template has been created: n " + new_path + new_panel + excel_ext)
python excel vba python-3.x excel-vba
python excel vba python-3.x excel-vba
edited Nov 16 '18 at 11:05
Pᴇʜ
24.8k63052
24.8k63052
asked Nov 15 '18 at 18:56
Ivan GutierrezIvan Gutierrez
285
285
Edit your Question and show the value of+ excel_ext
.
– stovfl
Nov 15 '18 at 19:32
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01
add a comment |
Edit your Question and show the value of+ excel_ext
.
– stovfl
Nov 15 '18 at 19:32
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01
Edit your Question and show the value of
+ excel_ext
.– stovfl
Nov 15 '18 at 19:32
Edit your Question and show the value of
+ excel_ext
.– stovfl
Nov 15 '18 at 19:32
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01
add a comment |
1 Answer
1
active
oldest
votes
First of all, try to open Excel file in safe mode. If it will open then, you work on COM Add-in. Try to delete them and then, open the file.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326195%2fexcel-file-is-being-corrupted-when-trying-to-modify-1-cell-using-openpyxl-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, try to open Excel file in safe mode. If it will open then, you work on COM Add-in. Try to delete them and then, open the file.
add a comment |
First of all, try to open Excel file in safe mode. If it will open then, you work on COM Add-in. Try to delete them and then, open the file.
add a comment |
First of all, try to open Excel file in safe mode. If it will open then, you work on COM Add-in. Try to delete them and then, open the file.
First of all, try to open Excel file in safe mode. If it will open then, you work on COM Add-in. Try to delete them and then, open the file.
answered Nov 28 '18 at 7:16
Sean SmithSean Smith
253
253
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326195%2fexcel-file-is-being-corrupted-when-trying-to-modify-1-cell-using-openpyxl-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Edit your Question and show the value of
+ excel_ext
.– stovfl
Nov 15 '18 at 19:32
@stovfl excel_ext = ".xlsm"
– Ivan Gutierrez
Nov 19 '18 at 4:09
Sorry, can't reproduce your Issue.
– stovfl
Nov 19 '18 at 9:01