Excel file is being corrupted when trying to modify 1 cell using openpyxl python.










1















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)









share|improve this question
























  • 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















1















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)









share|improve this question
























  • 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













1












1








1


1






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)









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























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



    );













    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer



























      0














      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.






      share|improve this answer

























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 7:16









        Sean SmithSean Smith

        253




        253





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto