Read text in particular location with python - python

I am working with a table with many rows (lets call them a,b,c,d, etc) and with the actual value this rows have in a particular column (that value is a bit 0,1 that can change continously). So a screenshot in a particular moment could be something like this:
Table
Table is not in excel or any other program that let me work with pandas or any similar library. So I have to read the screen directly.
User pass to the program the row that he wants to know and then the program must search for this column and return the value. I am using pyautogui. I am able to find the column and do a "tab" in order to place in the column that I want but I don't know how to read the value there. I tried locateAllOnScreen and seems to not work well (also I dont want all the "1" in the screen, I only want to know if that particular column of that particular row is a 1 or a 0).
Another method that I have though is to do Ctrl+C in the column and then create a txt and paste the value there. After that close the txt and read it with python, but I want to know if there is any other way better than this one.

Related

How to find or create headers in xlsx in Python?

I am writing a code that has a lot of keys (AVIGILON, HID, FARGO, GENETEC, RS2, SYNERGIS HARDWARE etc). What I want to do is that whenever I get a value along with that key in a dictionary, I want to go to the xlsx file and find the header,and if found, place it under. But if I do not find the header, (Let's say the FARGO is being fetched for the first time and we need to enter it with a value of 1010), I want to create a new header of FARGO and place the 1010 value under it.
enter image description here
enter image description here
I am not sure how to do it. I did with other method which is long and time consuming. Is there any better and faster way to accomplish the goal?

How can I make a chart that automatically adds info with openpyxl?

I'm trying to create a tracker of stuff I do every day, like the amount of water I drink, how much I exercise, read, whatever, and store that info in two sheets, one with 365-day info and one with all the days
I also want to have an excel graph that I can quickly take a look at (meaning I don't want to have to set it up every time I want to see it). Doing that for the 365 days thing should be easy by just setting a locked range of 365 cells, but in any case it would only look pretty once I've been using it for some months.
This webpage shows exactly how to do it when you input the info manually, but I'm using openpyxl to input the info for me via a telegram bot. I tried doing that then adding a value right below the table with code and it doesn't work.
My theory is that once you call that cell it gets emptied of any kind of attributes (format) it might have before setting a value.
Example: If you make the cells (B2:D4) have all borders and then execute ws['C3'] = 5, it will remove the borders of that cell because you didn't explicitly told Excel to "keep them" (or, more accurate, set them again)
The example can be fixed using openpyxl.styles, but how do I make excel "check", or add new values to the existing table? I assume that if I get them to join the table, they will be added to the graph too.
This is a personal project, not an assignment or anything, so if there's another way to do the same, I'm okay with that.
Edit: I've been playing with dir(ws.tables['Table1']) and found an (attribute?) called insertRow, but I can't find anything at all that explains what it does, only how it works (Boolean that allows None). I tried manually changing it from None to True and then trying again, but when I opened the file it said it needed to be repaired, and when repaired it added the value but didn't make it join the table...

How can I format google sheets so I can export my data properly?

I plan to make an educational web game. I have thousands of trivia questions I need to write down in a way that can be easily transferred out and automatically organized based on their column, at a later date.
I was suggested to use google sheets so I can later export as a .csv, and that should be easy to work with for a developer. When i exported a .csv and opened it in Panda python the a column was cut off and 1 column was used as a 'header', not just a normal entry https://imgur.com/a/olcpVO8. This obviously wont work and seems to be an issue.
Should I just leave the first row and column empty and work around the issue? I don't want to write thousands of sets only to find out I did this the wrong way. Can anyone give any insight into whether this is my best option and how I should best format it?
I have to write Questions(1), Answers(4), Explanations(1) per entry
I hope this makes sense, thanks for your time.
I tried doing this and have no issue at all using the exported CSV from Google Sheets, using the same data as in your example.
In my opinion, whatever software you're using in your second screenshot is your issue, it seems like its removing numbers from the first row because that should be your header row. Check around in your software for options like, "First column contains headers" or "Use row 1 as Header" and make sure these aren't being used.

Extract cells/Ranges information(col,row) from selected area in active Excel sheet with Python win32com

For my python script, there is one missing simple trick when I want to take data from Excel with Python win32com.
I just want to know how to get selected cells information, e.g. col/row for my python script. For example I could specify the range as shown below, but I simply cannot do the same thing to the selected/active cells.
ws.Range("B1:AM167").CopyPicture()
Does someone help me with this?
I am quite new to win32, so I still do not know how to find correct method/property etc...
Try Application.Selection.
The returned object type depends on the current selection (for
example, if a cell is selected, this property returns a Range object).
The Selection property returns Nothing if nothing is selected.

Append a new Column with Pandas Python

I currently have a python script which pulls in Analytics data and churns out a CSV. I want to be able to add in a column in after the CSV has been created. I know which column number it has to go in and I would also like to populate each cell in that column as far down as the CSV goes.
Is there any simple script, from Pandas, that would allow me to add on a column and populate the cells based on a loop I create?
If any further information is needed please let me know, i'm still very new to python :)
Cheers

Categories