2020-08-23 14:15:53 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
2024-05-22 00:21:11 +00:00
|
|
|
package reference ;import (_g "errors";_eg "fmt";_c "github.com/unidoc/unioffice/spreadsheet/update";_e "regexp";_ea "strconv";_b "strings";);
|
|
|
|
|
|
|
|
// Update updates reference to point one of the neighboring columns with respect to the update type after removing a row/column.
|
|
|
|
func (_be *ColumnReference )Update (updateType _c .UpdateAction )*ColumnReference {switch updateType {case _c .UpdateActionRemoveColumn :_ag :=_be ;_ag .ColumnIdx =_be .ColumnIdx -1;_ag .Column =IndexToColumn (_ag .ColumnIdx );return _ag ;default:return _be ;
|
|
|
|
};};func _fef (_fd string )(string ,string ,error ){_gf :="";_bc :=_b .LastIndex (_fd ,"\u0021");if _bc > -1{_gf =_fd [:_bc ];_fd =_fd [_bc +1:];if _gf ==""{return "","",_g .New ("\u0049n\u0076a\u006c\u0069\u0064\u0020\u0073h\u0065\u0065t\u0020\u006e\u0061\u006d\u0065");
|
|
|
|
};};return _gf ,_fd ,nil ;};
|
|
|
|
|
|
|
|
// ColumnReference is a parsed reference to a column. Input is of the form 'A',
|
|
|
|
// '$C', etc.
|
|
|
|
type ColumnReference struct{ColumnIdx uint32 ;Column string ;AbsoluteColumn bool ;SheetName string ;};var _dd =_e .MustCompile ("^\u005b\u0061\u002d\u007aA-\u005a]\u0028\u005b\u0061\u002d\u007aA\u002d\u005a\u005d\u003f\u0029\u0024");
|
|
|
|
|
|
|
|
// ParseRangeReference splits a range reference of the form "A1:B5" into its
|
|
|
|
// components.
|
|
|
|
func ParseRangeReference (s string )(_gc ,_aca CellReference ,_ddf error ){_afe ,_ff ,_ddf :=_fef (s );if _ddf !=nil {return CellReference {},CellReference {},_ddf ;};_aef :=_b .Split (_ff ,"\u003a");if len (_aef )!=2{return CellReference {},CellReference {},_g .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006eg\u0065\u0020\u0066\u006frm\u0061\u0074");
|
|
|
|
};if _afe !=""{_aef [0]=_afe +"\u0021"+_aef [0];_aef [1]=_afe +"\u0021"+_aef [1];};_bb ,_ddf :=ParseCellReference (_aef [0]);if _ddf !=nil {return CellReference {},CellReference {},_ddf ;};_bf ,_ddf :=ParseCellReference (_aef [1]);if _ddf !=nil {return CellReference {},CellReference {},_ddf ;
|
|
|
|
};return _bb ,_bf ,nil ;};
|
|
|
|
|
|
|
|
// ParseColumnRangeReference splits a range reference of the form "A:B" into its
|
|
|
|
// components.
|
|
|
|
func ParseColumnRangeReference (s string )(_caa ,_ccf ColumnReference ,_ed error ){_fa :="";_cf :=_b .Split (s ,"\u0021");if len (_cf )==2{_fa =_cf [0];s =_cf [1];};_cfg :=_b .Split (s ,"\u003a");if len (_cfg )!=2{return ColumnReference {},ColumnReference {},_g .New ("i\u006ev\u0061\u006c\u0069\u0064\u0020\u0072\u0061\u006eg\u0065\u0020\u0066\u006frm\u0061\u0074");
|
|
|
|
};if _fa !=""{_cfg [0]=_fa +"\u0021"+_cfg [0];_cfg [1]=_fa +"\u0021"+_cfg [1];};_cfa ,_ed :=ParseColumnReference (_cfg [0]);if _ed !=nil {return ColumnReference {},ColumnReference {},_ed ;};_ba ,_ed :=ParseColumnReference (_cfg [1]);if _ed !=nil {return ColumnReference {},ColumnReference {},_ed ;
|
|
|
|
};return _cfa ,_ba ,nil ;};
|
|
|
|
|
|
|
|
// String returns a string representation of CellReference.
|
|
|
|
func (_ce CellReference )String ()string {_ef :=make ([]byte ,0,4);if _ce .AbsoluteColumn {_ef =append (_ef ,'$');};_ef =append (_ef ,_ce .Column ...);if _ce .AbsoluteRow {_ef =append (_ef ,'$');};_ef =_ea .AppendInt (_ef ,int64 (_ce .RowIdx ),10);return string (_ef );
|
|
|
|
};
|
|
|
|
|
|
|
|
// ParseColumnReference parses a column reference of the form 'Sheet1!A' and splits it
|
|
|
|
// into sheet name and column segments.
|
|
|
|
func ParseColumnReference (s string )(ColumnReference ,error ){s =_b .TrimSpace (s );if len (s )< 1{return ColumnReference {},_g .New ("\u0063\u006f\u006c\u0075\u006d\u006e \u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065\u0020\u006d\u0075\u0073\u0074\u0020\u0068\u0061\u0076\u0065\u0020a\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u006f\u006e\u0065\u0020\u0063\u0068a\u0072a\u0063\u0074\u0065\u0072");
|
|
|
|
};_ae :=ColumnReference {};_fe ,_af ,_afa :=_fef (s );if _afa !=nil {return ColumnReference {},_afa ;};if _fe !=""{_ae .SheetName =_fe ;};if _af [0]=='$'{_ae .AbsoluteColumn =true ;_af =_af [1:];};if !_dd .MatchString (_af ){return ColumnReference {},_g .New ("\u0063\u006f\u006c\u0075\u006dn\u0020\u0072\u0065\u0066\u0065\u0072\u0065\u006e\u0063\u0065\u0020\u006d\u0075s\u0074\u0020\u0062\u0065\u0020\u0062\u0065\u0074\u0077\u0065\u0065\u006e\u0020\u0041\u0020\u0061\u006e\u0064\u0020\u005a\u005a");
|
|
|
|
};_ae .Column =_af ;_ae .ColumnIdx =ColumnToIndex (_ae .Column );return _ae ,nil ;};
|
2024-05-04 18:48:06 +00:00
|
|
|
|
2024-05-08 13:54:39 +00:00
|
|
|
// IndexToColumn maps a column number to a column name (e.g. 0 = A, 1 = B, 26 = AA)
|
2024-05-22 00:21:11 +00:00
|
|
|
func IndexToColumn (col uint32 )string {var _ac [64+1]byte ;_efa :=len (_ac );_ge :=col ;const _agc =26;for _ge >=_agc {_efa --;_afd :=_ge /_agc ;_ac [_efa ]=byte ('A'+uint (_ge -_afd *_agc ));_ge =_afd -1;};_efa --;_ac [_efa ]=byte ('A'+uint (_ge ));return string (_ac [_efa :]);
|
2024-05-08 13:54:39 +00:00
|
|
|
};
|
2024-02-17 03:37:07 +00:00
|
|
|
|
2024-05-22 00:21:11 +00:00
|
|
|
// ColumnToIndex maps a column to a zero based index (e.g. A = 0, B = 1, AA = 26)
|
|
|
|
func ColumnToIndex (col string )uint32 {col =_b .ToUpper (col );_cd :=uint32 (0);for _ ,_de :=range col {_cd *=26;_cd +=uint32 (_de -'A'+1);};return _cd -1;};
|
|
|
|
|
2024-02-17 03:37:07 +00:00
|
|
|
// CellReference is a parsed reference to a cell. Input is of the form 'A1',
|
|
|
|
// '$C$2', etc.
|
2024-05-04 18:48:06 +00:00
|
|
|
type CellReference struct{RowIdx uint32 ;ColumnIdx uint32 ;Column string ;AbsoluteColumn bool ;AbsoluteRow bool ;SheetName string ;};
|
2024-02-17 03:37:07 +00:00
|
|
|
|
2024-05-08 13:54:39 +00:00
|
|
|
// ParseCellReference parses a cell reference of the form 'A10' and splits it
|
|
|
|
// into column/row segments.
|
2024-05-22 00:21:11 +00:00
|
|
|
func ParseCellReference (s string )(CellReference ,error ){s =_b .TrimSpace (s );if len (s )< 2{return CellReference {},_g .New ("\u0063\u0065\u006c\u006c\u0020\u0072\u0065\u0066e\u0072\u0065\u006ece\u0020\u006d\u0075\u0073\u0074\u0020h\u0061\u0076\u0065\u0020\u0061\u0074\u0020\u006c\u0065\u0061\u0073\u0074\u0020\u0074\u0077o\u0020\u0063\u0068\u0061\u0072\u0061\u0063\u0074e\u0072\u0073");
|
|
|
|
};_aa :=CellReference {};_efe ,_d ,_f :=_fef (s );if _f !=nil {return CellReference {},_f ;};if _efe !=""{_aa .SheetName =_efe ;};if s [0]=='$'{_aa .AbsoluteColumn =true ;_d =_d [1:];};_cc :=-1;_ccb :for _db :=0;_db < len (_d );_db ++{switch {case _d [_db ]>='0'&&_d [_db ]<='9'||_d [_db ]=='$':_cc =_db ;
|
|
|
|
break _ccb ;};};switch _cc {case 0:return CellReference {},_eg .Errorf ("\u006e\u006f\u0020\u006cet\u0074\u0065\u0072\u0020\u0070\u0072\u0065\u0066\u0069\u0078\u0020\u0069\u006e\u0020%\u0073",_d );case -1:return CellReference {},_eg .Errorf ("\u006eo\u0020d\u0069\u0067\u0069\u0074\u0073\u0020\u0069\u006e\u0020\u0025\u0073",_d );
|
|
|
|
};_aa .Column =_d [0:_cc ];if _d [_cc ]=='$'{_aa .AbsoluteRow =true ;_cc ++;};_aa .ColumnIdx =ColumnToIndex (_aa .Column );_cb ,_f :=_ea .ParseUint (_d [_cc :],10,32);if _f !=nil {return CellReference {},_eg .Errorf ("e\u0072\u0072\u006f\u0072 p\u0061r\u0073\u0069\u006e\u0067\u0020r\u006f\u0077\u003a\u0020\u0025\u0073",_f );
|
|
|
|
};if _cb ==0{return CellReference {},_eg .Errorf ("\u0065\u0072\u0072\u006f\u0072\u0020\u0070\u0061\u0072\u0073i\u006e\u0067\u0020\u0072\u006f\u0077\u003a \u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u0030");};_aa .RowIdx =uint32 (_cb );
|
|
|
|
return _aa ,nil ;};
|
2023-12-28 15:53:06 +00:00
|
|
|
|
2024-04-03 00:10:23 +07:00
|
|
|
// String returns a string representation of ColumnReference.
|
2024-05-22 00:21:11 +00:00
|
|
|
func (_da ColumnReference )String ()string {_df :=make ([]byte ,0,4);if _da .AbsoluteColumn {_df =append (_df ,'$');};_df =append (_df ,_da .Column ...);return string (_df );};
|
2023-06-10 07:12:37 +00:00
|
|
|
|
2023-12-28 15:53:06 +00:00
|
|
|
// Update updates reference to point one of the neighboring cells with respect to the update type after removing a row/column.
|
2024-05-22 00:21:11 +00:00
|
|
|
func (_ega *CellReference )Update (updateType _c .UpdateAction )*CellReference {switch updateType {case _c .UpdateActionRemoveColumn :_ca :=_ega ;_ca .ColumnIdx =_ega .ColumnIdx -1;_ca .Column =IndexToColumn (_ca .ColumnIdx );return _ca ;default:return _ega ;
|
|
|
|
};};
|