I have to read an online Excelsheet into a dataframe. This data frame consists formatted text in several cells. For example, as shown in Figure 1, a cell might contain a paragraph, followed by a space and a few bullet points etc. How can I read the Excelsheet as a Pandas data frame while preserving this text style format in each cell.
The auth_and_return_excel
function, (more specifically pd.read_excel(bytes_file_obj)
), the pd. is written to read the online Excelsheet into a dataframe. However, this doesn’t preserve the styling.
def auth_and_return_excel(site_url, uname, password, file_url):
ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(uname, password):
ctx = ClientContext(site_url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print('Authenticated into sharepoint as: ', web.properties['Title'])
else:
print(ctx_auth.get_last_error())
response = File.open_binary(ctx, file_url)
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0) # set file object to start
data = pd.read_excel(bytes_file_obj)
return data
4