errors.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // Copyright 2016 - 2023 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to and
  6. // read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
  7. // writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
  8. // Supports complex components by high compatibility, and provided streaming
  9. // API for generating or reading data from a worksheet with huge amounts of
  10. // data. This library needs Go version 1.16 or later.
  11. package excelize
  12. import (
  13. "errors"
  14. "fmt"
  15. )
  16. // newInvalidColumnNameError defined the error message on receiving the
  17. // invalid column name.
  18. func newInvalidColumnNameError(col string) error {
  19. return fmt.Errorf("invalid column name %q", col)
  20. }
  21. // newInvalidRowNumberError defined the error message on receiving the invalid
  22. // row number.
  23. func newInvalidRowNumberError(row int) error {
  24. return fmt.Errorf("invalid row number %d", row)
  25. }
  26. // newInvalidCellNameError defined the error message on receiving the invalid
  27. // cell name.
  28. func newInvalidCellNameError(cell string) error {
  29. return fmt.Errorf("invalid cell name %q", cell)
  30. }
  31. // newInvalidExcelDateError defined the error message on receiving the data
  32. // with negative values.
  33. func newInvalidExcelDateError(dateValue float64) error {
  34. return fmt.Errorf("invalid date value %f, negative values are not supported", dateValue)
  35. }
  36. // newInvalidTableNameError defined the error message on receiving the invalid
  37. // table name.
  38. func newInvalidTableNameError(name string) error {
  39. return fmt.Errorf("invalid table name %q", name)
  40. }
  41. // newUnsupportedChartType defined the error message on receiving the chart
  42. // type are unsupported.
  43. func newUnsupportedChartType(chartType ChartType) error {
  44. return fmt.Errorf("unsupported chart type %d", chartType)
  45. }
  46. // newUnzipSizeLimitError defined the error message on unzip size exceeds the
  47. // limit.
  48. func newUnzipSizeLimitError(unzipSizeLimit int64) error {
  49. return fmt.Errorf("unzip size exceeds the %d bytes limit", unzipSizeLimit)
  50. }
  51. // newInvalidStyleID defined the error message on receiving the invalid style
  52. // ID.
  53. func newInvalidStyleID(styleID int) error {
  54. return fmt.Errorf("invalid style ID %d", styleID)
  55. }
  56. // newFieldLengthError defined the error message on receiving the field length
  57. // overflow.
  58. func newFieldLengthError(name string) error {
  59. return fmt.Errorf("field %s must be less than or equal to 255 characters", name)
  60. }
  61. // newCellNameToCoordinatesError defined the error message on converts
  62. // alphanumeric cell name to coordinates.
  63. func newCellNameToCoordinatesError(cell string, err error) error {
  64. return fmt.Errorf("cannot convert cell %q to coordinates: %v", cell, err)
  65. }
  66. // newNoExistSheetError defined the error message on receiving the non existing
  67. // sheet name.
  68. func newNoExistSheetError(name string) error {
  69. return fmt.Errorf("sheet %s does not exist", name)
  70. }
  71. // newNotWorksheetError defined the error message on receiving a sheet which
  72. // not a worksheet.
  73. func newNotWorksheetError(name string) error {
  74. return fmt.Errorf("sheet %s is not a worksheet", name)
  75. }
  76. // newStreamSetRowError defined the error message on the stream writer
  77. // receiving the non-ascending row number.
  78. func newStreamSetRowError(row int) error {
  79. return fmt.Errorf("row %d has already been written", row)
  80. }
  81. // newViewIdxError defined the error message on receiving a invalid sheet view
  82. // index.
  83. func newViewIdxError(viewIndex int) error {
  84. return fmt.Errorf("view index %d out of range", viewIndex)
  85. }
  86. var (
  87. // ErrStreamSetColWidth defined the error message on set column width in
  88. // stream writing mode.
  89. ErrStreamSetColWidth = errors.New("must call the SetColWidth function before the SetRow function")
  90. // ErrStreamSetPanes defined the error message on set panes in stream
  91. // writing mode.
  92. ErrStreamSetPanes = errors.New("must call the SetPanes function before the SetRow function")
  93. // ErrColumnNumber defined the error message on receive an invalid column
  94. // number.
  95. ErrColumnNumber = fmt.Errorf(`the column number must be greater than or equal to %d and less than or equal to %d`, MinColumns, MaxColumns)
  96. // ErrColumnWidth defined the error message on receive an invalid column
  97. // width.
  98. ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
  99. // ErrOutlineLevel defined the error message on receive an invalid outline
  100. // level number.
  101. ErrOutlineLevel = errors.New("invalid outline level")
  102. // ErrCoordinates defined the error message on invalid coordinates tuples
  103. // length.
  104. ErrCoordinates = errors.New("coordinates length must be 4")
  105. // ErrExistsSheet defined the error message on given sheet already exists.
  106. ErrExistsSheet = errors.New("the same name sheet already exists")
  107. // ErrTotalSheetHyperlinks defined the error message on hyperlinks count
  108. // overflow.
  109. ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
  110. // ErrInvalidFormula defined the error message on receive an invalid
  111. // formula.
  112. ErrInvalidFormula = errors.New("formula not valid")
  113. // ErrAddVBAProject defined the error message on add the VBA project in
  114. // the workbook.
  115. ErrAddVBAProject = errors.New("unsupported VBA project")
  116. // ErrMaxRows defined the error message on receive a row number exceeds maximum limit.
  117. ErrMaxRows = errors.New("row number exceeds maximum limit")
  118. // ErrMaxRowHeight defined the error message on receive an invalid row
  119. // height.
  120. ErrMaxRowHeight = fmt.Errorf("the height of the row must be less than or equal to %d points", MaxRowHeight)
  121. // ErrImgExt defined the error message on receive an unsupported image
  122. // extension.
  123. ErrImgExt = errors.New("unsupported image extension")
  124. // ErrWorkbookFileFormat defined the error message on receive an
  125. // unsupported workbook file format.
  126. ErrWorkbookFileFormat = errors.New("unsupported workbook file format")
  127. // ErrMaxFilePathLength defined the error message on receive the file path
  128. // length overflow.
  129. ErrMaxFilePathLength = errors.New("file path length exceeds maximum limit")
  130. // ErrUnknownEncryptMechanism defined the error message on unsupported
  131. // encryption mechanism.
  132. ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
  133. // ErrUnsupportedEncryptMechanism defined the error message on unsupported
  134. // encryption mechanism.
  135. ErrUnsupportedEncryptMechanism = errors.New("unsupported encryption mechanism")
  136. // ErrUnsupportedHashAlgorithm defined the error message on unsupported
  137. // hash algorithm.
  138. ErrUnsupportedHashAlgorithm = errors.New("unsupported hash algorithm")
  139. // ErrUnsupportedNumberFormat defined the error message on unsupported number format
  140. // expression.
  141. ErrUnsupportedNumberFormat = errors.New("unsupported number format token")
  142. // ErrPasswordLengthInvalid defined the error message on invalid password
  143. // length.
  144. ErrPasswordLengthInvalid = errors.New("password length invalid")
  145. // ErrParameterRequired defined the error message on receive the empty
  146. // parameter.
  147. ErrParameterRequired = errors.New("parameter is required")
  148. // ErrParameterInvalid defined the error message on receive the invalid
  149. // parameter.
  150. ErrParameterInvalid = errors.New("parameter is invalid")
  151. // ErrDefinedNameScope defined the error message on not found defined name
  152. // in the given scope.
  153. ErrDefinedNameScope = errors.New("no defined name on the scope")
  154. // ErrDefinedNameDuplicate defined the error message on the same name
  155. // already exists on the scope.
  156. ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
  157. // ErrCustomNumFmt defined the error message on receive the empty custom number format.
  158. ErrCustomNumFmt = errors.New("custom number format can not be empty")
  159. // ErrFontLength defined the error message on the length of the font
  160. // family name overflow.
  161. ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
  162. // ErrFontSize defined the error message on the size of the font is invalid.
  163. ErrFontSize = fmt.Errorf("font size must be between %d and %d points", MinFontSize, MaxFontSize)
  164. // ErrSheetIdx defined the error message on receive the invalid worksheet
  165. // index.
  166. ErrSheetIdx = errors.New("invalid worksheet index")
  167. // ErrUnprotectSheet defined the error message on worksheet has set no
  168. // protection.
  169. ErrUnprotectSheet = errors.New("worksheet has set no protect")
  170. // ErrUnprotectSheetPassword defined the error message on remove sheet
  171. // protection with password verification failed.
  172. ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")
  173. // ErrGroupSheets defined the error message on group sheets.
  174. ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
  175. // ErrDataValidationFormulaLength defined the error message for receiving a
  176. // data validation formula length that exceeds the limit.
  177. ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
  178. // ErrDataValidationRange defined the error message on set decimal range
  179. // exceeds limit.
  180. ErrDataValidationRange = errors.New("data validation range exceeds limit")
  181. // ErrCellCharsLength defined the error message for receiving a cell
  182. // characters length that exceeds the limit.
  183. ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
  184. // ErrOptionsUnzipSizeLimit defined the error message for receiving
  185. // invalid UnzipSizeLimit and UnzipXMLSizeLimit.
  186. ErrOptionsUnzipSizeLimit = errors.New("the value of UnzipSizeLimit should be greater than or equal to UnzipXMLSizeLimit")
  187. // ErrSave defined the error message for saving file.
  188. ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write")
  189. // ErrAttrValBool defined the error message on marshal and unmarshal
  190. // boolean type XML attribute.
  191. ErrAttrValBool = errors.New("unexpected child of attrValBool")
  192. // ErrSparklineType defined the error message on receive the invalid
  193. // sparkline Type parameters.
  194. ErrSparklineType = errors.New("parameter 'Type' must be 'line', 'column' or 'win_loss'")
  195. // ErrSparklineLocation defined the error message on missing Location
  196. // parameters
  197. ErrSparklineLocation = errors.New("parameter 'Location' is required")
  198. // ErrSparklineRange defined the error message on missing sparkline Range
  199. // parameters
  200. ErrSparklineRange = errors.New("parameter 'Range' is required")
  201. // ErrSparkline defined the error message on receive the invalid sparkline
  202. // parameters.
  203. ErrSparkline = errors.New("must have the same number of 'Location' and 'Range' parameters")
  204. // ErrSparklineStyle defined the error message on receive the invalid
  205. // sparkline Style parameters.
  206. ErrSparklineStyle = errors.New("parameter 'Style' must between 0-35")
  207. // ErrWorkbookPassword defined the error message on receiving the incorrect
  208. // workbook password.
  209. ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
  210. // ErrSheetNameInvalid defined the error message on receive the sheet name
  211. // contains invalid characters.
  212. ErrSheetNameInvalid = errors.New("the sheet can not contain any of the characters :\\/?*[or]")
  213. // ErrSheetNameSingleQuote defined the error message on the first or last
  214. // character of the sheet name was a single quote.
  215. ErrSheetNameSingleQuote = errors.New("the first or last character of the sheet name can not be a single quote")
  216. // ErrSheetNameBlank defined the error message on receive the blank sheet
  217. // name.
  218. ErrSheetNameBlank = errors.New("the sheet name can not be blank")
  219. // ErrSheetNameLength defined the error message on receiving the sheet
  220. // name length exceeds the limit.
  221. ErrSheetNameLength = fmt.Errorf("the sheet name length exceeds the %d characters limit", MaxSheetNameLength)
  222. // ErrTableNameLength defined the error message on receiving the table name
  223. // length exceeds the limit.
  224. ErrTableNameLength = fmt.Errorf("the table name length exceeds the %d characters limit", MaxFieldLength)
  225. // ErrCellStyles defined the error message on cell styles exceeds the limit.
  226. ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
  227. // ErrUnprotectWorkbook defined the error message on workbook has set no
  228. // protection.
  229. ErrUnprotectWorkbook = errors.New("workbook has set no protect")
  230. // ErrUnprotectWorkbookPassword defined the error message on remove workbook
  231. // protection with password verification failed.
  232. ErrUnprotectWorkbookPassword = errors.New("workbook protect password not match")
  233. )