-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXLS-REPLACE.CELL.DATA.py
43 lines (43 loc) · 2.44 KB
/
XLS-REPLACE.CELL.DATA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#--
#-- ************************************************************************************************************:
#-- ********************************************* REPLACE EXCEL DATA *******************************************:
#-- ************************************************************************************************************:
#-- Author: JBALLARD (JEB) :
#-- Date: 2023.2.18 :
#-- Script: XLS-REPLACE.CELL.DATA.py :
#-- Purpose: A python script that replaces particular text within an EXCEL spreadsheet. :
#-- Class: python -m pip install Spire.Pdf; python3 -m pip install Spire.Pdf :
#-- Class: python -m pip install Spire.Xls; python3 -m pip install Spire.Xls :
#-- Version: 1.0 :
#-- ************************************************************************************************************:
#-- ************************************************************************************************************:
#--
#-- ********************************************************:
#-- DEFINE PARAMS, CONSTANTS, CONFIG PATHS, IMPORT CLASSES :
#-- ********************************************************:
from spire.pdf import *
from spire.xls import *
from spire.xls.common import *
#--
#-- GENERATE WORKBOOK OBJECT:
workbook = Workbook()
workbook.LoadFromFile("2024.6-MS.SECURITY.xlsx")
sheetCount = 8
#--
#-- RETRIEVE CELLS CONTAINING SPECIFIED TEXT:
for i in range(sheetCount):
sheet = workbook.Worksheets[i]
ranges = sheet.FindAll("KB5", FindType.Text, ExcelFindOptions.none) #-- MatchEntireCellContent)
#-- ITERATE THROUGH RETRIEVED CELLS:
for range in ranges:
#-- REPLACE TEXT:
range.Text = ""
range.Style.Color = Color.get_Yellow()
#--
#-- SAVE NEW EXCEL FILE:
workbook.SaveToFile("2024.7-MS.SECURITY.xlsx", ExcelVersion.Version2016)
workbook.Dispose()
#--
#-- ********************************************************:
#-- END OF PYTHON SCRIPT :
#-- ********************************************************: