11import microsoftExcel from "../../microsoft_excel.app.mjs" ;
2- import {
3- parseObject , getColumnLetter ,
4- } from "../../common/utils.mjs" ;
2+ import { getColumnLetter } from "../../common/utils.mjs" ;
53
64export default {
75 key : "microsoft_excel-add-row" ,
@@ -41,6 +39,34 @@ export default {
4139 description : "An array of values for the new row. Each item in the array represents one cell. E.g. `[1, 2, 3]`" ,
4240 } ,
4341 } ,
42+ methods : {
43+ isArrayString ( str ) {
44+ return typeof str === "string" && ( ( str . startsWith ( "[" ) && str . endsWith ( "]" ) ) || ( ( str . startsWith ( "[[" ) || str . startsWith ( "[ [" ) ) && ( str . endsWith ( "]]" ) || str . endsWith ( "] ]" ) ) ) ) ;
45+ } ,
46+ convertStringToArray ( str ) {
47+ const arrayString = str . match ( / \[ \[ ? ( .* ?) \] ? \] / ) [ 1 ] ;
48+ return arrayString . split ( "," ) ;
49+ } ,
50+ parseValues ( columnCount ) {
51+ let values = this . values ;
52+ if ( Array . isArray ( this . values ) ) {
53+ if ( Array . isArray ( this . values [ 0 ] ) ) {
54+ values = this . values [ 0 ] ;
55+ } else if ( this . isArrayString ( this . values [ 0 ] ) ) {
56+ values = this . convertStringToArray ( this . values [ 0 ] ) ;
57+ }
58+ } else {
59+ if ( this . isArrayString ( this . values ) ) {
60+ values = this . convertStringToArray ( this . values ) ;
61+ }
62+ }
63+
64+ if ( values . length < columnCount ) {
65+ values . length = columnCount ;
66+ }
67+ return values ;
68+ } ,
69+ } ,
4470 async run ( { $ } ) {
4571 const {
4672 address, columnCount,
@@ -53,10 +79,7 @@ export default {
5379 // get next row range
5480 const match = address . match ( / ^ ( .+ ! ) ? ( [ A - Z ] + ) ( \d + ) : ( [ A - Z ] + ) ( \d + ) $ / ) ;
5581 const nextRow = parseInt ( match [ 5 ] , 10 ) + 1 ;
56- const values = parseObject ( this . values ) ;
57- if ( values . length < columnCount ) {
58- values . length = columnCount ;
59- }
82+ const values = this . parseValues ( columnCount ) ;
6083 const colEnd = getColumnLetter ( values . length ) ;
6184 const range = `A${ nextRow } :${ colEnd } ${ nextRow } ` ;
6285
0 commit comments