Skip to content

Commit 65155c8

Browse files
committed
ISSUE-CELLSCLOUD-13504: Add Example Code about data cleaning, split excel, text processing.
1 parent d54b947 commit 65155c8

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

.github/workflows/sdkbuild2run.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ jobs:
3434
cd examples
3535
python .\Example_QuickStart.py
3636
python .\Example_TextProcessing.py
37+
python .\Example_TextProcessing_40.py
3738
python .\Example_CheckExcel.py
3839
python .\Example_CloudStorageManagement.py
3940
python .\Example_ConvertChartToImage.py
4041
python .\Example_ConvertRangeToImage.py
4142
python .\Example_ConvertExcel.py
4243
python .\Example_Management.py
44+
python .\Example_DataCleaning.py
45+
python .\Example_ExcelSplit.py

examples/BookText.xlsx

2.3 KB
Binary file not shown.

examples/Example_DataCleaning.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import base64
2+
import os
3+
4+
from asposecellscloud.apis.cells_api import CellsApi
5+
from asposecellscloud.models import *
6+
from asposecellscloud.requests import *
7+
8+
# If no environment variables are configured, please obtain the ClientId and ClientSecret from https://dashboard.aspose.cloud/#/applications and replace the following values:
9+
# instance = CellsApi('YourClientId','YourClientSecret')
10+
instance = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret'))
11+
# Remove all blank columns of BookText.xlsx, save as TempBookText.xlsx
12+
instance.remove_spreadsheet_blank_columns(RemoveSpreadsheetBlankColumnsRequest("BookText.xlsx"),local_outpath = "TempBookText.xlsx")
13+
# Remove all blank rows of TmpBookText.xlsx, save it.
14+
instance.remove_spreadsheet_blank_rows(RemoveSpreadsheetBlankRowsRequest("TempBookText.xlsx"),local_outpath = "TempBookText.xlsx")
15+
# Remove all blank worksheets of TempBookText.xlsx, save it.
16+
instance.remove_spreadsheet_blank_worksheets(RemoveSpreadsheetBlankWorksheetsRequest("TempBookText.xlsx"),local_outpath = "TempBookText.xlsx")
17+
# Remove all duplicates of TempBookText.xlsx, save it.
18+
instance.remove_duplicates(RemoveDuplicatesRequest("TempBookText.xlsx"),local_outpath = "TempBookText.xlsx")

examples/Example_ExcelSplit.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import base64
2+
import os
3+
import zipfile
4+
5+
from asposecellscloud.apis.cells_api import CellsApi
6+
from asposecellscloud.models import *
7+
from asposecellscloud.requests import *
8+
9+
EmployeeSalesSummaryXlsx = "EmployeeSalesSummary.xlsx"
10+
CompanySalesXlsx = "CompanySales.xlsx"
11+
# Get Cells Cloud SDK instance
12+
# If no environment variables are configured, please obtain the ClientId and ClientSecret from https://dashboard.aspose.cloud/#/applications and replace the following values:
13+
# instance = CellsApi('YourClientId','YourClientSecret')
14+
instance = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret'))
15+
instance.split_spreadsheet(SplitSpreadsheetRequest(EmployeeSalesSummaryXlsx),local_outpath ="split.zip")
16+
with zipfile.ZipFile("split.zip",'r') as zip_ref:
17+
zip_ref.extractall(".")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
3+
from asposecellscloud.apis.cells_api import CellsApi
4+
from asposecellscloud.models import *
5+
from asposecellscloud.requests import *
6+
7+
# If no environment variables are configured, please obtain the ClientId and ClientSecret from https://dashboard.aspose.cloud/#/applications and replace the following values:
8+
# instance = CellsApi('YourClientId','YourClientSecret')
9+
instance = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret'))
10+
11+
# The default value of the trim character is a blank space. Specify a specific location. Remove excess spaces between words.
12+
instance.trim_character(TrimCharacterRequest("BookText.xlsx", worksheet = "HumanResources", range ="A1:C12" , trim_space_between_word_to1 = True) ,local_outpath = "out1.xlsx")
13+
# The default value of the trim character is a blank space. Specify a specific location. Remove excess spaces between words. Only remove leading spaces.
14+
instance.trim_character(TrimCharacterRequest("BookText.xlsx", worksheet = "Text", range ="J6:J6" ,trim_trailing = False, trim_space_between_word_to1 = True) ,local_outpath = "out2.xlsx")
15+
# The default value of the trim character is a blank space. Specify a specific location. Remove excess spaces between words. Only remove leading spaces. Remove all line breaks.
16+
instance.trim_character(TrimCharacterRequest("BookText.xlsx", worksheet = "Text", range ="J7:J7" ,trim_trailing = False, trim_space_between_word_to1 = True,remove_all_line_breaks =True) ,local_outpath = "out3.xlsx")
17+
# Uppercase every string in the selected range.
18+
instance.update_word_case(UpdateWordCaseRequest("BookText.xlsx", "UpperCase", worksheet = "Text", range ="J7:J7" ) , local_outpath = "out4.xlsx")
19+
# Lowercase every string in the selected range.
20+
instance.update_word_case(UpdateWordCaseRequest("out4.xlsx", "LowerCase", worksheet = "Text", range ="J7:J7" ) , local_outpath = "out5.xlsx")
21+
# ProperCase every string in the selected range.
22+
instance.update_word_case(UpdateWordCaseRequest("out5.xlsx", "ProperCase", worksheet = "Text", range ="J7:J7" ) , local_outpath = "out6.xlsx")
23+
# SentenceCase every string in the selected range.
24+
instance.update_word_case(UpdateWordCaseRequest("out5.xlsx", "SentenceCase", worksheet = "Text", range ="J7:J7" ) , local_outpath = "out7.xlsx")
25+
26+
# Prefix every string in the selected range with "Aspose.Cells".
27+
instance.add_text( AddTextRequest("BookText.xlsx", "Aspose.Cells", "AtTheBeginning", "") , local_outpath = "out8.xlsx" )
28+
# Insert an exclamation mark immediately after the specified substring within every string in the selected range.
29+
instance.add_text( AddTextRequest("BookText.xlsx", "!", "AfterText", "hellow word") , local_outpath = "out9.xlsx" )
30+
# Append an exclamation mark to every string in the selected range.
31+
instance.add_text( AddTextRequest("BookText.xlsx", "!", "AtTheEnd", "", worksheet = "Text", range ="A1:J7" ,skip_empty_cells=False ) , local_outpath = "out10.xlsx" )
32+
33+
# convert_text_type: ConvertNumberToText,ConvertCharacters,ConvertLinebreak,ConvertWriteSpace,ConvertAccentedChars
34+
# Convert all numbers in the selected range to text. If worksheet and range are empty, the entire workbook is processed.
35+
instance.convert_text(ConvertTextRequest("BookText.xlsx", "ConvertNumberToText", "", ""), local_outpath = "out11.xlsx")
36+
# Replace every '1' in the selected range with 'Aspose.Cells'. If worksheet and range are empty, the entire workbook is processed.
37+
instance.convert_text(ConvertTextRequest("out11.xlsx", "ConvertCharacters", "1", "Aspose.Cells" , worksheet="Text", range="C9:F13"), local_outpath = "out12.xlsx")
38+
# Replace all line breaks in the selected range with the specified character.
39+
instance.convert_text(ConvertTextRequest("out12.xlsx", "ConvertLinebreak", "", "Linebreak"), local_outpath = "out13.xlsx")
40+
# Replace all blank space in the selected range with the specified character.
41+
instance.convert_text(ConvertTextRequest("out13.xlsx", "ConvertWriteSpace", "", "WriteSpace"), local_outpath = "out14.xlsx")
42+
43+
# ExtractTextType: ExtractFirstCharacter, ExtractFirstWord, ExtractLastCharacter, ExtractLastWord, ExtractTextBefore, ExtractTextAfter, ExtractBetweenSpecifiedCharacters, ExtractAllNumbers, GetTextFromAnyPosition
44+
#
45+
# instance.extract_text(ExtractTextRequest("BookText.xlsx", "ExtractTextBefore", ";","","","","I2:I11" ,worksheet= "HumanResources",range="G2:G11" ) , local_outpath = "out15.xlsx")

0 commit comments

Comments
 (0)