"com_error: (-2147417851, 'The server threw an exception.', None, None)"
Asked Answered
E

2

6

I need to copy data from three excel files & paste into three different excel files.

Error:
     ('F', 'C:\\Users\\jmp655972\\Desktop\\SOFTWARE DEVELOPMENT\\Folder Creation               Format\\Base Vehicle Laden\\Steady State\\Continous Test Data\\LH Turn\\test_1.csv')
Pass
('F', 'C:\\Users\\jmp655972\\Desktop\\SOFTWARE DEVELOPMENT\\Folder Creation Format\\Base Vehicle Laden\\Steady State\\Continous Test Data\\LH Turn\\test_2.csv')

Traceback (most recent call last):
  File "C:\Users\jmp655972\Desktop\Handling_Analysis_Software\main.py", line 120, in <module>
    filescheck(fileCount)
  File "C:\Users\jmp655972\Desktop\Handling_Analysis_Software\main.py", line 115, in filescheck
    readFilesAndCopyData(excelObj,"roll","1",csvfile)
  File "C:\Users\jmp655972\Desktop\Handling_Analysis_Software\main.py", line 62, in readFilesAndCopyData
    workbook = excel.Workbooks.Open(filetoOpen)
  File "C:\Python27\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x6.py", line 34940, in Open
    , Converter, AddToMru, Local, CorruptLoad)
com_error: (-2147417851, 'The server threw an exception.', None, None

def openExcel():
excel = client.Dispatch("Excel.Application")
excel.Visible = 1
return excel;



def readFilesAndCopyData(excel,testtype,vehicletype,filetoOpen):
    currworkingdirectory = os.getcwd()
    print ("F",filetoOpen)
    workbook = excel.Workbooks.Open(filetoOpen)
    worksheets = workbook.Worksheets(1)
    if testtype == "roll":
        if vehicletype == "1":
            print ("Pass")
            worksheets.Range("E:E,H:H,I:I").Select()
            worksheets.Range("E:E,H:H,I:I").Copy()
        else:
            worksheets.Range("L:L,O:O,P:P").Select()
            worksheets.Range("L:L,O:O,P:P").Copy()
    elif testtype == "slip":
        if vehicletype == "1":
            worksheets.Range("E:E,G:G").Select()
            worksheets.Range("E:E,G:G").Copy()
        else:
            worksheets.Range("E:E,G:G").Select()
            worksheets.Range("E:E,G:G").Copy()
    else:
        print("No Test Data Found")

    workbook.Close
    pasteCopiedData(excel)
    counter + 1 
Emden answered 19/11, 2013 at 9:28 Comment(0)
J
0

I had the same issue when was trying to copy a column from one sheet to another sheet in the same workbook. But while doing so I had 2 other workbooks opened. I thought server error might mean some sort of performance issue. So I tried to first close the other two workbooks (which were not required) and then do the copy function.

I think this resolves the issue since I have not got the error again.

Jenine answered 13/5, 2023 at 11:2 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ottoottoman
L
-1

I had the same error message while trying to automate Excel work. Specifically, a line of code which was supposed to open an Excel file threw this error. The reason seemed to be the fact the file path (directory + file name) was way too long. The error was gone when I renamed folders and file name to give them shorter name.

Limousine answered 16/7, 2019 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.