|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import base64 |
| 4 | +from asposecellscloud.apis.cells_api import CellsApi |
| 5 | +from asposecellscloud.models import * |
| 6 | +from asposecellscloud.requests import * |
| 7 | + |
| 8 | + |
| 9 | +EmployeeSalesSummaryXlsx = "EmployeeSalesSummary.xlsx" |
| 10 | +RemoteFolder = "PythonSDK" |
| 11 | +# Get Cells Cloud SDK instance |
| 12 | +instance = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret')) |
| 13 | + |
| 14 | +# Convert a local Excel file to another format file directly. |
| 15 | +response = instance.put_convert_workbook(PutConvertWorkbookRequest( EmployeeSalesSummaryXlsx, 'pdf')) |
| 16 | +shutil.move( response ,"EmployeeSalesSummary1.pdf") |
| 17 | + |
| 18 | +# Upload a local Excel file to Cells Cloud Storage. |
| 19 | +instance.upload_file( UploadFileRequest(EmployeeSalesSummaryXlsx, "PythonSDK/EmployeeSalesSummary.xlsx")) |
| 20 | +# Convert an Excel file of Cells Cloud to another format file. |
| 21 | +response = instance.get_workbook( GetWorkbookRequest(EmployeeSalesSummaryXlsx , format='pdf' , folder=RemoteFolder) ) |
| 22 | +shutil.move( response ,"EmployeeSalesSummary2.pdf") |
| 23 | + |
| 24 | +#Save an Excel file of Cells Cloud as another format file of Cells Cloud. |
| 25 | +instance.post_workbook_save_as( PostWorkbookSaveAsRequest( EmployeeSalesSummaryXlsx ,newfilename= "PythonSDK/EmployeeSalesSummary.pdf" ,folder=RemoteFolder )) |
| 26 | + |
| 27 | +# Convert a local Excel file to pdf file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 28 | +response = instance.post_convert_workbook_to_pdf( PostConvertWorkbookToPDFRequest( EmployeeSalesSummaryXlsx ,)) |
| 29 | +filedata = base64.b64decode(response.file_content) |
| 30 | +with open("EmployeeSalesSummary.pdf", "wb") as file: |
| 31 | + file.write(filedata) |
| 32 | + |
| 33 | +# Convert a local Excel file to pdf file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 34 | +response = instance.post_convert_workbook_to_json( PostConvertWorkbookToJsonRequest( EmployeeSalesSummaryXlsx ,)) |
| 35 | +filedata = base64.b64decode(response.file_content) |
| 36 | +with open("EmployeeSalesSummary.json", "wb") as file: |
| 37 | + file.write(filedata) |
| 38 | + |
| 39 | + |
| 40 | +# Convert a local Excel file to docx file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 41 | +response = instance.post_convert_workbook_to_docx( PostConvertWorkbookToDocxRequest( EmployeeSalesSummaryXlsx ,)) |
| 42 | +filedata = base64.b64decode(response.file_content) |
| 43 | +with open("EmployeeSalesSummary.docx", "wb") as file: |
| 44 | + file.write(filedata) |
| 45 | + |
| 46 | +# Convert a local Excel file to png file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 47 | +response = instance.post_convert_workbook_to_png( PostConvertWorkbookToPNGRequest( EmployeeSalesSummaryXlsx ,)) |
| 48 | +filedata = base64.b64decode(response.file_content) |
| 49 | +with open("EmployeeSalesSummary.png", "wb") as file: |
| 50 | + file.write(filedata) |
| 51 | + |
| 52 | +# Convert a local Excel file to pptx file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 53 | +response = instance.post_convert_workbook_to_pptx(PostConvertWorkbookToPptxRequest(EmployeeSalesSummaryXlsx, )) |
| 54 | +filedata = base64.b64decode(response.file_content) |
| 55 | +with open("EmployeeSalesSummary.pptx", "wb") as file: |
| 56 | + file.write(filedata) |
| 57 | + |
| 58 | +# Convert a local Excel file to html file directly. The return value is a file info object, which includes of file name, file content(base64string), and file size. |
| 59 | +response = instance.post_convert_workbook_to_html(PostConvertWorkbookToHtmlRequest(EmployeeSalesSummaryXlsx, )) |
| 60 | +filedata = base64.b64decode(response.file_content) |
| 61 | +with open("EmployeeSalesSummary.html", "wb") as file: |
| 62 | + file.write(filedata) |
| 63 | + |
| 64 | +# Convert a worksheet of a local Excel file to another format file directly. Set query parameters : print_headings, one_page_per_sheet |
| 65 | +response = instance.get_worksheet_with_format( GetWorksheetWithFormatRequest(EmployeeSalesSummaryXlsx, "Sales", folder ="PythonSDK", format="png", print_headings=True , one_page_per_sheet= False ) ) |
| 66 | +shutil.move( response ,"EmployeeSalesSummary_Sales.png") |
| 67 | + |
| 68 | +# Convert a local Excel file's specified worksheet page index directly to another format file. Set query parameters : print_headings, one_page_per_sheet |
| 69 | +response = instance.get_worksheet_with_format( GetWorksheetWithFormatRequest(EmployeeSalesSummaryXlsx, "Sales", folder ="PythonSDK", format="png", page_index= 1 , print_headings=True , one_page_per_sheet= False ) ) |
| 70 | +shutil.move( response ,"EmployeeSalesSummary_Sales_PageIndex.png") |
| 71 | + |
| 72 | +# Convert a local Excel file's specified worksheet cells area directly to another format file. Set query parameters : print_headings, one_page_per_sheet |
| 73 | +response = instance.get_worksheet_with_format( GetWorksheetWithFormatRequest(EmployeeSalesSummaryXlsx, "Sales", folder ="PythonSDK", format="png", area="B5:L36" ,print_headings=True , one_page_per_sheet= False ) ) |
| 74 | +shutil.move( response ,"EmployeeSalesSummary_Sales_area.png") |
| 75 | + |
| 76 | +# Advanced Conversion allows you to flexibly set page parameters and save parameters |
| 77 | +dataSource = DataSource( data_source_type = 'CloudFileSystem' , data_path = RemoteFolder +'/' +EmployeeSalesSummaryXlsx ) |
| 78 | +saveOptions = PdfSaveOptions( save_format ='pdf' , one_page_per_sheet = True ) |
| 79 | +convertWorkbookOptions = ConvertWorkbookOptions( data_source= dataSource , convert_format = 'Pdf' ,save_options= saveOptions ) |
| 80 | +response = instance.post_convert_workbook( PostConvertWorkbookRequest( convert_workbook_options=convertWorkbookOptions ) ) |
| 81 | +filedata = base64.b64decode(response.file_content) |
| 82 | +with open("EmployeeSalesSummary3.pdf", "wb") as file: |
| 83 | + file.write(filedata) |
0 commit comments