I have a excel table sheet1 data in a cell A1, 1 minute intervals will automatically update the data at a time, now, I want to gain data about each update automatically by the PYTHON, and preserved, PS: the excel table is open has been in use state,
Specific how should write code, please? Look forward to your help, thank you!
CodePudding user response:
Just saved, you can read the data, make a abnormal judgment can, lest was saved, error reading file.
The from openpyxl import load_workbook From the time the import sleep # the cycle on demand change For I in range (10) : Try: Wb=load_workbook (' data/data. XLSX) Sheet_temp=wb [wb sheetnames [0]] Print (sheet_temp [' A1] value) Wb. Close () Except: Pass # this time as needed to change Sleep (5) CodePudding user response:
Thank you for your help first,
However, the code can only access the A1 cell initial data, then this A1 cell data is constantly update change (ps: this EXCEL worksheets must be in the condition of open and run), this code cannot obtain the updated data,
I hope we can get you further solutions to help, thank you!
reference 1/f, old coconut response: just saved, you can read the data, make a abnormal judgment can, lest was saved, error reading file. The from openpyxl import load_workbook From the time the import sleep # the cycle on demand change For I in range (10) : Try: Wb=load_workbook (' data/data. XLSX) Sheet_temp=wb [wb sheetnames [0]] Print (sheet_temp [' A1] value) Wb. Close () Except: Pass # this time as needed to change Sleep (5) CodePudding user response:
I tried repeatedly to A1 data, and save, Can display normal ah, If only change, do not save, that will not be able to use the conventional method, can only study the win32, direct access to EXCEL program information, CodePudding user response:
I verify again, at present this code applies to cell A1 is going to save your work after each data update list, so you can get the latest data, however, our reality is that this piece of work table just has been in the open state, due to the A1 cell data changes very frequently, really can't do the high frequency of preservation, Do not save the worksheet, and the solution? Thank you refer to the second floor weixin_43712138 response: thank you for your help first, However, the code can only access the A1 cell initial data, then this A1 cell data is constantly update change (ps: this EXCEL worksheets must be in the condition of open and run), this code cannot obtain the updated data, I hope we can get you further solutions to help, thank you! Quote: refer to 1st floor old coconut response: Just saved, you can read the data, make a abnormal judgment can, lest was saved, error reading file. The from openpyxl import load_workbook From the time the import sleep # the cycle on demand change For I in range (10) : Try: Wb=load_workbook (' data/data. XLSX) Sheet_temp=wb [wb sheetnames [0]] Print (sheet_temp [' A1] value) Wb. Close () Except: Pass # this time as needed to change Sleep (5) CodePudding user response:
Yes, it can save, save, no, 5555555555 Win32 is a what thing, please? I am a novice, don't understand, please advice! Thank you reference old coconut reply: 3/f I tried repeatedly to A1 data, and save, Can display normal ah, If only change, do not save, that will not be able to use the conventional method, can only study the win32, direct access to EXCEL program information, CodePudding user response:
Simple solution, after open the file, set the excel automatically saved, CodePudding user response:
Mainly is the file is very big, each save cost a certain time, and in the process of preservation, must have affected the normal operation of other EXCEL! refer to 6th floor old coconut response: simple solution, after open the file, set the excel automatically saved, CodePudding user response:
And the EXCEL automatically save time interval can be set for 1 minute, refer to 7th floor weixin_43712138 response: mainly file is very big, each save cost a certain time, and in the process of preservation, must have affected the normal operation of other EXCEL! Quote: refer to the sixth floor of the old coconut reply: Simple solution, after open the file, set the excel automatically saved, CodePudding user response:
Automatically save the set 1 minutes, or not, you must manually save the python code to obtain data, CodePudding user response:
Since excel is always open, may be to use excel macro operation? As the background to save multiple CSV, in order to make sure python can obtain the dynamic data of high frequency CodePudding user response:
Yes, you enable macros, need to constantly refresh data, Is there a way to enable the macro premise, to get the data? Thank you very much! The references to the tenth floor chuifengde response: since excel is always open, may be to use excel macro operation? As the background to save multiple CSV, in order to make sure python can obtain the dynamic data of high frequency CodePudding user response:
Then in the case of the refresh data in vba, write a disk text file, as the middle stand by python reads it CodePudding user response:
Text file to date/time for the filename, content change only write data, indicating the data line and column number in the excel CodePudding user response:
If it is preserved, it can be directly performed by vba, python reads all province, CodePudding user response:
Convenient to write a code for me? I am a little white, don't understand! This macro is his stay at the moment, also won't deal with the refer to 12 floor chuifengde reply: that in the case of the refresh data in vba, write a disk text file, as the middle stand by python constantly read it CodePudding user response:
Don't know right no, if can, direct access to the data source in python, need not excel table number, if this number, also is to simulate preservation, nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull