@@ -19,6 +19,7 @@ import {
19
19
import { getCellAddress } from "../taskpane" ;
20
20
import { useState } from "react" ;
21
21
22
+
22
23
// ProJets brand color
23
24
const brandColor = "#4B0DFF" ;
24
25
const accentColor = "#FF6B00" ; // Orange accent color from the image
@@ -137,7 +138,7 @@ const App = () => {
137
138
const styles = useStyles ( ) ;
138
139
const [ selectedTab , setSelectedTab ] = useState ( "read" ) ;
139
140
const [ fullPluginMode , setFullPluginMode ] = useState ( "main" ) ; // Tracks the mode within Full Plugin tab
140
-
141
+
141
142
// Read section
142
143
const inputId = useId ( "input" ) ;
143
144
const inputId2 = useId ( "input" ) ;
@@ -178,79 +179,90 @@ const App = () => {
178
179
try {
179
180
const workbook = await Excel . run ( async ( context ) => {
180
181
var sheets = context . workbook . worksheets ;
181
- sheets . load ( "items" ) ;
182
- await context . sync ( ) ;
183
182
184
183
const worksheets = [ ] ;
184
+ var worksheet = sheets . getLast ( ) ;
185
185
186
- for ( var worksheet of sheets . items ) {
186
+ do {
187
187
resetProcessedRows ( ) ;
188
188
incrementWorksheet ( ) ;
189
+ worksheet . load ( "name" )
189
190
190
- const usedRange = worksheet . getUsedRange ( ) ;
191
- usedRange . load ( ) ;
192
- const usedRow = usedRange . getLastRow ( ) ;
193
- const usedCol = usedRange . getLastColumn ( ) ;
194
-
195
- usedRow . load ( "rowIndex" ) ;
196
- usedCol . load ( "columnIndex" ) ;
191
+ var usedRange = worksheet . getUsedRange ( ) ;
192
+ var lastColumn = usedRange . getLastColumn ( ) ;
193
+ var lastRow = usedRange . getLastRow ( ) ;
194
+ lastColumn . load ( "columnIndex" ) ;
195
+ lastRow . load ( "RowIndex" ) ;
197
196
await context . sync ( ) ;
198
197
199
- const range = worksheet . getRangeByIndexes ( 0 , 0 , usedRow . rowIndex + 1 , usedCol . columnIndex ) ;
198
+ const range = worksheet . getRangeByIndexes ( 0 , 0 , lastRow . rowIndex , lastColumn . columnIndex ) ;
199
+ usedRange . untrack ( ) ;
200
+ lastColumn . untrack ( ) ;
201
+ lastRow . untrack ( ) ;
202
+
200
203
range . load ( [
201
- "values" ,
202
- "formulas" ,
204
+ "columnCount" ,
203
205
"formulasR1C1" ,
204
- "address" ,
205
206
"numberFormat" ,
206
- "format/font" ,
207
207
"rowCount" ,
208
- "columnCount" ,
209
208
] ) ;
210
-
209
+ var properties = range . getCellProperties ( {
210
+ address : true ,
211
+ format : {
212
+ fill : {
213
+ color : true
214
+ } ,
215
+ font : {
216
+ bold : true ,
217
+ color : true ,
218
+ italic : true ,
219
+ name : true ,
220
+ size : true ,
221
+ strikethrough : true ,
222
+ underline : true
223
+ }
224
+ }
225
+ } ) ;
211
226
await context . sync ( ) ;
212
227
213
- const addresses = range . address . split ( ":" ) [ 0 ] . split ( "!" ) [ 1 ] ; // Get starting address
214
- const baseColumn = addresses . replace ( / [ 0 - 9 ] / g, "" ) ;
215
- const baseRow = parseInt ( addresses . replace ( / [ ^ 0 - 9 ] / g, "" ) ) ;
216
228
const worksheetData = {
217
229
name : worksheet . name ,
218
230
cells : { } ,
219
231
} ;
232
+
220
233
setWorksheetRows ( range . rowCount ) ;
221
234
for ( let row = 0 ; row < range . rowCount ; row ++ ) {
222
235
incrementProcessedRows ( ) ;
223
236
for ( let col = 0 ; col < range . columnCount ; col ++ ) {
224
- const cellAddress = getCellAddress ( baseColumn , baseRow , row , col ) ;
225
- const cellFont = range . getCell ( row , col ) . format . font ;
226
- const cellFill = range . getCell ( row , col ) . format . fill ;
227
- cellFont . load ( [ "bold" , "color" , "italic" , "name" , "size" , "underline" , "backgroundColor" ] ) ;
228
- cellFill . load ( [ "color" ] ) ;
229
- await context . sync ( ) ;
230
-
231
237
const cellData = {
232
238
formulaR1C1 : range . formulasR1C1 [ row ] [ col ] ,
233
- address : cellAddress ,
239
+ address : properties . value [ row ] [ col ] . address ,
234
240
rowIndex : row ,
235
- columnIndex : col ,
241
+ columnIndex : col ,
236
242
format : {
237
243
font : {
238
- name : cellFont . name ,
239
- size : cellFont . size ,
240
- bold : cellFont . bold ,
241
- italic : cellFont . italic ,
242
- underline : cellFont . underline ,
243
- color : cellFont . color ,
244
+ bold : properties . value [ row ] [ col ] . format . font . bold ,
245
+ color : properties . value [ row ] [ col ] . format . font . color ,
246
+ italic : properties . value [ row ] [ col ] . format . font . italic ,
247
+ name : properties . value [ row ] [ col ] . format . font . name ,
248
+ size : properties . value [ row ] [ col ] . format . font . size ,
249
+ strikethrough : properties . value [ row ] [ col ] . format . font . strikethrough ,
250
+ underline : properties . value [ row ] [ col ] . format . font . underline ,
244
251
} ,
245
252
numberFormat : range . numberFormat [ row ] [ col ] ,
246
- backgroundColor : cellFill . color ,
253
+ backgroundColor : properties . value [ row ] [ col ] . format . fill . color ,
247
254
} ,
248
255
} ;
249
- worksheetData . cells [ cellAddress ] = cellData ;
256
+ worksheetData . cells [ properties . value [ row ] [ col ] . address ] = cellData ;
257
+
250
258
}
251
259
}
252
260
worksheets . push ( worksheetData ) ;
253
- }
261
+ console . log ( worksheetData ) ;
262
+
263
+ range . untrack ( ) ;
264
+ await context . sync ( ) ;
265
+ } while ( worksheet = worksheet . getPrevious ( ) ) ;
254
266
console . log ( worksheets ) ;
255
267
return worksheets ;
256
268
} ) ;
@@ -359,7 +371,7 @@ const App = () => {
359
371
setIsWriteLoading ( true ) ;
360
372
setWriteErrorMessage ( "" ) ;
361
373
e . preventDefault ( ) ;
362
-
374
+
363
375
try {
364
376
const formData = new FormData ( e . currentTarget ) ;
365
377
const textArea = formData . get ( "textArea" ) ;
0 commit comments