save style to google spreadsheet - pandas

I'm writting dataframes to google spreadsheets with gspread_dataframe, gspread. I'm trying to assign a yellow background to cells depends on the values with pandas style. https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
Is there a way to save the assigned background color to the google spreadsheet too?
Thanks

With this one, you can use gspread_formatting
from gspread_formatting import *
bGYellow = cellFormat(backgroundColor=color(1, 1, 0))
format_cell_range(worksheet, 'A1:E1', bGYellow)
Please see gspread-formatting for more details

Related

xlsxwriter modifying worksheet font

I need assistance modifying the font and size of excel spreadsheet from default to 'Arial' 9. I'm able to modify the header row, but unable to get the body of the spreadsheet to do the same. I'm using xlsxwriter, I'm sure it's something simple just not that familiar with xlsxwriter. See code below, any assistance greatly appreciated.
Pipeline_details.to_excel(writer1,
sheet_name ='Pipeline_Details',
startrow=1,
startcol=0,
header=False,
index=False)
workbook = writer1.book
worksheet = writer1.sheets['Pipeline Details']
(max_row, max_col) = Pipeline_details.shape
worksheet.autofilter(0,0,max_row, max_col - 1)
worksheer.hide_gridlines(2)
header_format = workbook_add.format({
'font_name': 'Arial',
'font_size': 9,
'bold': False,
'text_wrap': True})
for col_num, value in enumerate(Pipeline_details.columns.values):
worksheet.write(0, col_num, value, header_format)
cell_format = workbook.add_format({'font_name': 'Arial', 'font_size': 9})
writer1.save()
The docs for formatting while using pandas with xlsxwriter state the following:
XlsxWriter and Pandas provide very little support for formatting the output data from a dataframe apart from default formatting such as the header and index cells and any cells that contain dates or datetimes. In addition it isn’t possible to format any cells that already have a default format applied.
If you require very controlled formatting of the dataframe output then you would probably be better off using Xlsxwriter directly with raw data taken from Pandas.
That being said
It is possible to format any other, non date/datetime column data using set_column()
For an example using A notation, you'd execute this after writing your data to the worksheet:
worksheet.set_column('A:Z', None, format)
I'd try that first to see if you get anywhere with it. Otherwise I'd suggest writing your rows yourself and adding your format that way.

Is it possible to get the text from a text cell with a code cell in google colab?

I'm trying to make a word counter of my text cells. My idea was to somehow get the text from the text cells and then work the strings. I would like to know if it is possible.
Yup, here's an example:
https://colab.research.google.com/drive/1dxq_K3vgIYjxDL7DpxoHRfJEQbxThM57
The three cells do three things:
Authenticate for access to Drive.
Download the JSON content of the notebook.
Count the words for the markdown cells in the notebook.

Excel VBA : Use the color of a shape in an If/Then case

I have created a chart on Excel using macros. Each of the shapes on the chart is filled with a color according to its category. I was wondering if it is possible to use the color of the shapes in an If/Then case to perform different actions, such as displaying the shapes with specific colors only.
For example, something similar to:
If shape.Fill.ForeColor.SchemeColor = 1 Then
shape.delete
I have tried that, but it doesn't seem to do anything to my chart. Does anyone have an idea of how to do it?
Thank you !!
Did you try checking the color with the corresponding RGB value? Since SchemeColor depends on the current color scheme it might be looking for a different color than you'd expect

Forming a specific colour filled shape in powerpoint when importing a data from excel cell

I am a beginner in programming. I know how to import a data from excel to powerpoint in such a way that when I change the data in the cells in excel, the corresponding datas in the powerpoint changes as well.
But is there a way to create a specific shape (with specific colours) in powerpoint automatically for a range of data imported from excel.
For example, if I type the number 1 in excel, it should go to powerpoint as well and a square box with the colour green should be formed in power point slide with the number 1 in it.
If number 2, then yellow
and number 3 red
Any help would be deeply appreciated! Thanks in advance!
Without your code it is not possible to give you an example. I would look at
Add shape:
http://msdn.microsoft.com/en-us/library/office/ff744336%28v=office.15%29.aspx
Once you have the shape, you can color it, add text etc, see:
http://msdn.microsoft.com/en-us/library/office/ff744177%28v=office.15%29.aspx
Regards,
HP

Getting a merged cell width on Google Spreadsheet API

I'm using the Google Spreadsheet API to convert a document containing workers shifts into event calendars.
The only problem is that shifts are represented by merged cells according to days and hours (with days and hours as rows and different work slots as cols), and when I read a certain cell, which is merged and spans over 6 cells, I cannot get the cells certain width or its merged area.
For example:
If I try to get the values between (4C:4E) I will get "Bob, , ," and not "bob,bob,bob", and I cannot even find a way to know how many cells "bob" take.
Do you guys know how can I know how many cells the merged one spread to? Or at least it's total width.
Thanks in advance!
Download from google drive as html, see:
Get FontStyle information from Google spreadsheet into appengine
Drive driveService = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).build();
File file = driveService.files().get(this.spreadsheetKey).execute();
String downloadUrl = file.getExportLinks().get("application/pdf");
downloadUrl = downloadUrl.replaceFirst("exportFormat=pdf", "exportFormat=html");
downloadUrl = appendWorksheetGid(downloadUrl); // adds "&gid="+sheetGid
HttpResponse resp =
driveService.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
.execute();
System.out.println("downloadUrl:"+downloadUrl);
InputStream fileContent = resp.getContent();
extractStyleFromHtml(fileContent,downloadUrl);
extractStyleFromHtml uses Jsoup - (Jsoup impressed me)
It's not possible via spreadsheet API. I was looking for same. Google admits the same in their documentation.
The literal value of the cell element is the calculated value of the
cell, without formatting applied. If the cell contains a formula, the
calculated value is given here. The Spreadsheets API has no concept of
formatting, and thus cannot manipulate formatting of cells.
Related question:
Set cell format in Google Sheets spreadsheet using its API & Python
One alternate way can be to download the doc in excel format programmatically. It will contain formatting information. Then using excel API to extract the info.