from io import BytesIO
from azure.storage.blob import BlockBlobService
blobService = BlockBlobService(account_name="storageaccountname", account_key="Storage Key",protocol='https')
# sample = pd.DataFrame(sample_dict)
sample = pd_data_df
# Create a Pandas Excel writer using XlsxWriter as the engine.
output = BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
sample.to_excel(writer, sheet_name='Sheet1')
# Get the xlsxwriter workbook and worksheet objects.
workbook = writer.book
worksheet = writer.sheets['Sheet1']
# Add a format.
format1 = workbook.add_format({'bg_color': 'red'})
# Get the dimensions of the dataframe.
(max_row, max_col) = sample.shape
# Apply a conditional format to the required cell range.
worksheet.conditional_format(1, 1, max_row, max_col,
{'type': 'blanks',
'format': format1})
# Close the Pandas Excel writer and output the Excel file.
writer.save()
xlsx_data = output.getvalue()
blobService.create_blob_from_bytes(container_name,frolder_path_with_file_name, xlsx_data)
## Need to write xlsx_data to blob storage from here
1条答案
按热度按时间szqfcxe21#