react-native-nitro-xlsx 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +73 -0
  3. package/NitroXlsx.podspec +110 -0
  4. package/README.md +340 -0
  5. package/android/CMakeLists.txt +52 -0
  6. package/android/build.gradle +49 -0
  7. package/android/cpp-adapter.cpp +9 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/java/com/margelo/nitro/xlsx/NitroXlsxPackage.kt +22 -0
  10. package/cpp/HybridNitroXlsx.cpp +29 -0
  11. package/cpp/HybridNitroXlsx.hpp +19 -0
  12. package/cpp/HybridXlsxCellFormat.cpp +263 -0
  13. package/cpp/HybridXlsxCellFormat.hpp +111 -0
  14. package/cpp/HybridXlsxWorkbook.cpp +184 -0
  15. package/cpp/HybridXlsxWorkbook.hpp +41 -0
  16. package/cpp/HybridXlsxWorksheet.cpp +316 -0
  17. package/cpp/HybridXlsxWorksheet.hpp +86 -0
  18. package/nitro.json +19 -0
  19. package/nitrogen/generated/.gitattributes +1 -0
  20. package/nitrogen/generated/android/NitroXlsx+autolinking.cmake +84 -0
  21. package/nitrogen/generated/android/NitroXlsx+autolinking.gradle +27 -0
  22. package/nitrogen/generated/android/NitroXlsxOnLoad.cpp +49 -0
  23. package/nitrogen/generated/android/NitroXlsxOnLoad.hpp +34 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/xlsx/NitroXlsxOnLoad.kt +35 -0
  25. package/nitrogen/generated/ios/NitroXlsx+autolinking.rb +62 -0
  26. package/nitrogen/generated/ios/NitroXlsx-Swift-Cxx-Bridge.cpp +17 -0
  27. package/nitrogen/generated/ios/NitroXlsx-Swift-Cxx-Bridge.hpp +27 -0
  28. package/nitrogen/generated/ios/NitroXlsx-Swift-Cxx-Umbrella.hpp +38 -0
  29. package/nitrogen/generated/ios/NitroXlsxAutolinking.mm +35 -0
  30. package/nitrogen/generated/ios/NitroXlsxAutolinking.swift +16 -0
  31. package/nitrogen/generated/shared/c++/CellType.hpp +100 -0
  32. package/nitrogen/generated/shared/c++/HybridNitroXlsxSpec.cpp +23 -0
  33. package/nitrogen/generated/shared/c++/HybridNitroXlsxSpec.hpp +68 -0
  34. package/nitrogen/generated/shared/c++/HybridXlsxCellFormatSpec.cpp +62 -0
  35. package/nitrogen/generated/shared/c++/HybridXlsxCellFormatSpec.hpp +104 -0
  36. package/nitrogen/generated/shared/c++/HybridXlsxWorkbookSpec.cpp +27 -0
  37. package/nitrogen/generated/shared/c++/HybridXlsxWorkbookSpec.hpp +77 -0
  38. package/nitrogen/generated/shared/c++/HybridXlsxWorksheetSpec.cpp +69 -0
  39. package/nitrogen/generated/shared/c++/HybridXlsxWorksheetSpec.hpp +120 -0
  40. package/package.json +47 -0
  41. package/src/__mocks__/react-native-nitro-modules.ts +28 -0
  42. package/src/__mocks__/react-native.ts +1 -0
  43. package/src/__tests__/index.test.ts +141 -0
  44. package/src/index.ts +195 -0
  45. package/src/specs/NitroXlsx.nitro.ts +154 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Denis Cheung (https://github.com/zydbkqf)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,73 @@
1
+ OPEN SOURCE SOFTWARE ATTRIBUTION NOTICE
2
+ This software uses third-party open source components listed below, with full license text attached.
3
+
4
+ ================================================================================
5
+ 1. OpenXLSX
6
+ Repository: https://github.com/troldal/OpenXLSX
7
+ License: BSD 3-Clause License
8
+ Copyright (c) 2020 Kenneth Troldal Balslev
9
+
10
+ Full BSD 3-Clause License text:
11
+
12
+ BSD 3-Clause License
13
+
14
+ Copyright (c) 2020, Kenneth Troldal Balslev All rights reserved.
15
+
16
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
17
+
18
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
19
+
20
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
21
+
22
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ ================================================================================
27
+ 2. react-native-nitro-modules
28
+ Repository: https://github.com/mrousavy/nitro
29
+ Version: 0.58.3
30
+ License: MIT License
31
+ Copyright (c) 2024 Marc Rousavy
32
+
33
+ ================================================================================
34
+ 3. pugixml (OpenXLSX dependency)
35
+ Repository: https://github.com/zeux/pugixml
36
+ License: MIT License
37
+ Copyright (c) 2006-2024 Arseny Kapoulkine
38
+
39
+ ================================================================================
40
+ 4. Zippy (OpenXLSX dependency)
41
+ Repository: https://github.com/troldal/Zippy
42
+ License: MIT License
43
+ Copyright (c) 2019 Kenneth Troldal Balslev
44
+
45
+ ================================================================================
46
+ 5. miniz (OpenXLSX dependency)
47
+ Repository: https://github.com/richgel999/miniz
48
+ License: MIT License
49
+ Copyright (c) 2013-2014 RAD Game Tools and Valve Software
50
+ Copyright (c) 2010-2014 Rich Geldreich and Tenacious Software LLC
51
+
52
+ Full standard MIT License text:
53
+
54
+ MIT License
55
+
56
+ Copyright (c) 2024 Marc Rousavy
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ of this software and associated documentation files (the "Software"), to deal
59
+ in the Software without restriction, including without limitation the rights
60
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ copies of the Software, and to permit persons to whom the Software is
62
+ furnished to do so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in all
65
+ copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ SOFTWARE.
@@ -0,0 +1,110 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "NitroXlsx"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => "15.1" }
14
+ s.source = { :git => "", :tag => "#{s.version}" }
15
+
16
+ s.exclude_files = "cpp/tests/**/*"
17
+
18
+ s.source_files = [
19
+ "cpp/**/*.{h,hpp,cpp}",
20
+ "OpenXLSX/OpenXLSX/**/*.hpp",
21
+ "OpenXLSX/OpenXLSX/**/*.cpp",
22
+ "OpenXLSX/ThirdParty/pugixml/src/**/*.hpp",
23
+ "OpenXLSX/ThirdParty/pugixml/src/**/*.cpp",
24
+ "OpenXLSX/OpenXLSX/headers/detail/Zippy.hpp",
25
+ "OpenXLSX/ThirdParty/miniz/**/*.h",
26
+ "OpenXLSX/ThirdParty/miniz/**/*.c",
27
+ ]
28
+
29
+ s.private_header_files = [
30
+ "OpenXLSX/**/*.hpp",
31
+ "OpenXLSX/**/*.h",
32
+ ]
33
+
34
+ s.dependency "React"
35
+
36
+ s.pod_target_xcconfig = {
37
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
38
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
39
+ "DEFINES_MODULE" => "YES",
40
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
41
+ "OTHER_CFLAGS" => "$(inherited) -fmodules",
42
+ "OTHER_CPLUSPLUSFLAGS" => "$(inherited) -fmodules",
43
+ "HEADER_SEARCH_PATHS" => "$(inherited) ${PODS_TARGET_SRCROOT}/OpenXLSX ${PODS_TARGET_SRCROOT}/OpenXLSX/OpenXLSX ${PODS_TARGET_SRCROOT}/OpenXLSX/OpenXLSX/headers ${PODS_TARGET_SRCROOT}/OpenXLSX/ThirdParty/pugixml/src ${PODS_TARGET_SRCROOT}/OpenXLSX/ThirdParty/miniz",
44
+ }
45
+
46
+ s.user_target_xcconfig = {
47
+ "OTHER_CFLAGS" => "$(inherited) -fmodules",
48
+ "OTHER_CPLUSPLUSFLAGS" => "$(inherited) -fmodules",
49
+ "HEADER_SEARCH_PATHS" => "$(inherited) ${PODS_TARGET_SRCROOT}/OpenXLSX ${PODS_TARGET_SRCROOT}/OpenXLSX/OpenXLSX ${PODS_TARGET_SRCROOT}/OpenXLSX/OpenXLSX/headers ${PODS_TARGET_SRCROOT}/OpenXLSX/ThirdParty/pugixml/src ${PODS_TARGET_SRCROOT}/OpenXLSX/ThirdParty/miniz",
50
+ }
51
+
52
+ s.prepare_command = <<-CMD
53
+ if [ ! -d "OpenXLSX" ]; then
54
+ git clone --depth 1 --branch v0.5.1 https://github.com/troldal/OpenXLSX.git
55
+ fi
56
+ mkdir -p OpenXLSX/ThirdParty
57
+ if [ ! -d "OpenXLSX/ThirdParty/pugixml" ]; then
58
+ git clone --depth 1 --branch v1.15 https://github.com/zeux/pugixml.git OpenXLSX/ThirdParty/pugixml
59
+ fi
60
+ if [ ! -d "OpenXLSX/ThirdParty/miniz" ]; then
61
+ git clone --depth 1 --branch 3.0.2 https://github.com/richgel999/miniz.git OpenXLSX/ThirdParty/miniz
62
+ fi
63
+ if [ ! -f "OpenXLSX/ThirdParty/miniz/miniz_export.h" ]; then
64
+ cat > OpenXLSX/ThirdParty/miniz/miniz_export.h << 'EOF'
65
+ #ifndef MINIZ_EXPORT_H
66
+ #define MINIZ_EXPORT_H
67
+
68
+ #ifndef MINIZ_EXPORT
69
+ #define MINIZ_EXPORT
70
+ #endif
71
+
72
+ #ifndef MINIZ_DEPRECATED
73
+ #define MINIZ_DEPRECATED
74
+ #endif
75
+
76
+ #ifndef MINIZ_DEPRECATED_EXPORT
77
+ #define MINIZ_DEPRECATED_EXPORT MINIZ_EXPORT MINIZ_DEPRECATED
78
+ #endif
79
+
80
+ #ifndef MINIZ_NO_EXPORT
81
+ #define MINIZ_NO_EXPORT
82
+ #endif
83
+
84
+ #endif
85
+ EOF
86
+ fi
87
+ if [ ! -f "OpenXLSX/OpenXLSX/headers/OpenXLSX-Exports.hpp" ]; then
88
+ cat > OpenXLSX/OpenXLSX/headers/OpenXLSX-Exports.hpp << 'EOF'
89
+ #ifndef OPENXLSX_EXPORTS_HPP
90
+ #define OPENXLSX_EXPORTS_HPP
91
+
92
+ #ifndef OPENXLSX_EXPORT
93
+ #define OPENXLSX_EXPORT
94
+ #endif
95
+
96
+ #ifndef OPENXLSX_HIDDEN
97
+ #define OPENXLSX_HIDDEN
98
+ #endif
99
+
100
+ #endif
101
+ EOF
102
+ fi
103
+ if [ ! -d "OpenXLSX/OpenXLSX/headers/OpenXLSX" ]; then
104
+ cd OpenXLSX/OpenXLSX/headers && ln -sf . OpenXLSX && cd -
105
+ fi
106
+ CMD
107
+
108
+ load 'nitrogen/generated/ios/NitroXlsx+autolinking.rb'
109
+ add_nitrogen_files(s)
110
+ end
package/README.md ADDED
@@ -0,0 +1,340 @@
1
+ # react-native-nitro-xlsx
2
+
3
+ A React Native module for reading and writing Excel XLSX files using [OpenXLSX](https://github.com/troldal/OpenXLSX) via [react-native-nitro-modules](https://github.com/mrousavy/nitro).
4
+
5
+ ## Features
6
+
7
+ - 📊 Full Excel XLSX file creation support
8
+ - 📖 Read existing XLSX files (from file path or buffer)
9
+ - 📝 Formula support (with default values)
10
+ - 📅 Date/DateTime support
11
+ - 🖼️ Image insertion (from file path or buffer)
12
+ - 🎨 Rich formatting (fonts, colors, borders, alignment)
13
+ - 📄 Page setup (margins, orientation, headers/footers)
14
+ - 🔒 Sheet protection
15
+ - 📦 Export as ArrayBuffer - no file system required!
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ npm install react-native-nitro-xlsx
21
+ # or
22
+ yarn add react-native-nitro-xlsx
23
+ ```
24
+
25
+ ### iOS
26
+
27
+ ```sh
28
+ cd ios && pod install
29
+ ```
30
+
31
+ ### Android
32
+
33
+ No additional setup needed.
34
+
35
+ ## Usage
36
+
37
+ ### Creating a Workbook
38
+
39
+ ```typescript
40
+ import { NitroXlsx, Align, Colors, NumFormat } from 'react-native-nitro-xlsx';
41
+
42
+ // Create a new workbook (no file path needed!)
43
+ const workbook = NitroXlsx.createWorkbook();
44
+
45
+ // Add a worksheet
46
+ const sheet = workbook.addWorksheet('Sheet1');
47
+
48
+ // Create a cell format for headers
49
+ const headerFormat = workbook.addCellFormat();
50
+ headerFormat.setBold();
51
+ headerFormat.setFontColor(Colors.WHITE);
52
+ headerFormat.setFgColor(Colors.BLUE);
53
+ headerFormat.setAlign(Align.CENTER);
54
+
55
+ // Write headers
56
+ sheet.writeString(0, 0, 'Name', headerFormat);
57
+ sheet.writeString(0, 1, 'Price', headerFormat);
58
+ sheet.writeString(0, 2, 'Total', headerFormat);
59
+
60
+ // Write data
61
+ sheet.writeString(1, 0, 'Apple');
62
+ sheet.writeNumber(1, 1, 1.50);
63
+ sheet.writeFormula(1, 2, '=B2*1.1');
64
+
65
+ sheet.writeString(2, 0, 'Orange');
66
+ sheet.writeNumber(2, 1, 2.00);
67
+ sheet.writeFormula(2, 2, '=B3*1.1');
68
+
69
+ // Date example
70
+ const date = new Date(2024, 0, 15);
71
+ const excelDate = (date.getTime() / 86400000) + 25569; // Convert to Excel date
72
+ sheet.writeDatetime(3, 0, excelDate);
73
+
74
+ // Set column widths
75
+ sheet.setColumn(0, 0, 15);
76
+ sheet.setColumn(1, 2, 12);
77
+
78
+ // Get the buffer and do something with it
79
+ const buffer = await workbook.getBuffer();
80
+
81
+ // Save to file system, share, upload, etc.
82
+ // Example: FileSystem.writeAsStringAsync(path, buffer.toString('base64'));
83
+ // Example: Share.open({ url: 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,' + btoa(buffer) });
84
+ ```
85
+
86
+ ### Reading a Workbook
87
+
88
+ ```typescript
89
+ import { NitroXlsx } from 'react-native-nitro-xlsx';
90
+
91
+ // Open workbook from file path
92
+ const workbook = NitroXlsx.openWorkbook('/path/to/file.xlsx');
93
+
94
+ // Or open from buffer
95
+ // const workbook = NitroXlsx.openWorkbookFromBuffer(arrayBuffer);
96
+
97
+ // Get worksheet
98
+ const sheet = workbook.getWorksheet(0);
99
+ const sheetByName = workbook.getWorksheetByName('Sheet1');
100
+
101
+ // Get worksheet info
102
+ const name = sheet.getName();
103
+ const lastRow = sheet.getLastRow();
104
+ const lastCol = sheet.getLastColumn();
105
+
106
+ // Read cell values
107
+ for (let row = 0; row <= lastRow; row++) {
108
+ for (let col = 0; col <= lastCol; col++) {
109
+ const value = sheet.getCellValue(row, col);
110
+ const type = sheet.getCellType(row, col);
111
+ const strValue = sheet.getCellString(row, col);
112
+ console.log(`Cell [${row},${col}]: ${value} (type: ${type})`);
113
+ }
114
+ }
115
+
116
+ // Read cell format
117
+ const format = sheet.getCellFormat(0, 0);
118
+ const isBold = format.getIsBold();
119
+ const fontName = format.getFontName();
120
+ const fontSize = format.getFontSize();
121
+ ```
122
+
123
+ ## API
124
+
125
+ ### NitroXlsx
126
+
127
+ - `createWorkbook(): XlsxWorkbook` - Create a new workbook
128
+ - `openWorkbook(path: string): XlsxWorkbook` - Open workbook from file path
129
+ - `openWorkbookFromBuffer(buffer: ArrayBuffer): XlsxWorkbook` - Open workbook from buffer
130
+
131
+ ### XlsxWorkbook
132
+
133
+ - `addWorksheet(name?: string): XlsxWorksheet` - Add a new worksheet
134
+ - `getWorksheet(index: number): XlsxWorksheet` - Get worksheet by index
135
+ - `getWorksheetByName(name: string): XlsxWorksheet` - Get worksheet by name
136
+ - `getOrAddWorksheet(name: string): XlsxWorksheet` - Get or add worksheet
137
+ - `getWorksheetCount(): number` - Get number of worksheets
138
+ - `addCellFormat(): XlsxCellFormat` - Add a new cell format
139
+ - `getBuffer(): Promise<ArrayBuffer>` - Generate and return the XLSX file as a buffer
140
+
141
+ ### XlsxWorksheet
142
+
143
+ #### Basic Write Methods
144
+ | Method | Description |
145
+ |--------|-------------|
146
+ | `writeString(row, col, value, format?)` | Write a string |
147
+ | `writeNumber(row, col, value, format?)` | Write a number |
148
+ | `writeBoolean(row, col, value, format?)` | Write a boolean |
149
+ | `writeBlank(row, col, format?)` | Write a blank cell |
150
+
151
+ #### Formula Support
152
+ | Method | Description |
153
+ |--------|-------------|
154
+ | `writeFormula(row, col, formula, format?)` | Write a formula |
155
+ | `writeFormulaNum(row, col, formula, number, format?)` | Write a formula with number default |
156
+ | `writeFormulaString(row, col, formula, string, format?)` | Write a formula with string default |
157
+ | `writeFormulaBoolean(row, col, formula, boolean, format?)` | Write a formula with boolean default |
158
+ | `writeArrayFormula(firstRow, firstCol, lastRow, lastCol, formula, format?)` | Write an array formula |
159
+
160
+ #### Date/URL
161
+ | Method | Description |
162
+ |--------|-------------|
163
+ | `writeDatetime(row, col, datetime, format?)` | Write a datetime (Excel serial date number) |
164
+ | `writeURL(row, col, url, format?)` | Write a hyperlink |
165
+
166
+ #### Column/Row
167
+ | Method | Description |
168
+ |--------|-------------|
169
+ | `setColumn(firstCol, lastCol, width, format?)` | Set column properties |
170
+ | `setRow(row, height, format?)` | Set row properties |
171
+ | `setColumnHidden(firstCol, lastCol, hidden)` | Hide/show columns |
172
+ | `setRowHidden(row, hidden)` | Hide/show row |
173
+
174
+ #### Merge
175
+ | Method | Description |
176
+ |--------|-------------|
177
+ | `mergeRange(firstRow, firstCol, lastRow, lastCol, value, format?)` | Merge cells with string value |
178
+ | `mergeRangeNum(firstRow, firstCol, lastRow, lastCol, value, format?)` | Merge cells with number value |
179
+
180
+ #### Image
181
+ | Method | Description |
182
+ |--------|-------------|
183
+ | `insertImage(row, col, path, xOffset?, yOffset?, xScale?, yScale?)` | Insert image from file |
184
+ | `insertImageBuffer(row, col, buffer, extension, xOffset?, yOffset?, xScale?, yScale?)` | Insert image from buffer |
185
+
186
+ #### View
187
+ | Method | Description |
188
+ |--------|-------------|
189
+ | `freezePanes(row, col)` | Freeze panes |
190
+ | `splitPanes(row, col)` | Split panes |
191
+ | `setTabColor(color)` | Set tab color |
192
+ | `hide()` | Hide worksheet |
193
+ | `activate()` | Activate worksheet |
194
+ | `setFirstSheet()` | Set as first sheet |
195
+ | `protect(password?)` | Protect worksheet |
196
+
197
+ #### Page Setup
198
+ | Method | Description |
199
+ |--------|-------------|
200
+ | `setPortrait()` | Set portrait orientation |
201
+ | `setLandscape()` | Set landscape orientation |
202
+ | `setPaper(paperType)` | Set paper size |
203
+ | `setHeader(header)` | Set header |
204
+ | `setFooter(footer)` | Set footer |
205
+ | `setPrintArea(firstRow, firstCol, lastRow, lastCol)` | Set print area |
206
+ | `fitToPages(width, height)` | Fit to pages |
207
+ | `setZoom(scale)` | Set zoom level |
208
+ | `setGridlines(option)` | Set gridlines |
209
+ | `centerHorizontally()` | Center horizontally |
210
+ | `centerVertically()` | Center vertically |
211
+
212
+ #### Read Methods
213
+ | Method | Description |
214
+ |--------|-------------|
215
+ | `getCellValue(row, col)` | Get cell value (string \| number \| boolean \| null) |
216
+ | `getCellString(row, col)` | Get cell value as string |
217
+ | `getCellRawValue(row, col)` | Get raw cell value |
218
+ | `getCellType(row, col)` | Get cell type |
219
+ | `getCellFormat(row, col)` | Get cell format |
220
+ | `getRowCount()` | Get total row count |
221
+ | `getColumnCount()` | Get total column count |
222
+ | `getLastRow()` | Get last row index |
223
+ | `getLastColumn()` | Get last column index |
224
+ | `getName()` | Get worksheet name |
225
+
226
+ ### XlsxCellFormat
227
+
228
+ The `XlsxCellFormat` interface is based on OpenXLSX's `XLCellFormat` class and provides rich cell formatting capabilities.
229
+
230
+ #### Font
231
+ - `setFontName(name)`, `setFontSize(size)`, `setFontColor(color)`
232
+ - `setBold()`, `setItalic()`, `setUnderline(style?)`, `setStrikeout()`
233
+ - `setFontScript(style)` - Superscript/subscript
234
+
235
+ #### Alignment
236
+ - `setAlign(align)`, `setVerticalAlign(align)`
237
+ - `setTextWrap()`, `setRotation(angle)`
238
+ - `setIndent(level)`, `setShrink()`
239
+
240
+ #### Number Format
241
+ - `setNumFormat(format)` - Set custom format string
242
+ - `setNumFormatIndex(index)` - Set built-in format (use `NumFormat` constants)
243
+
244
+ #### Colors/Pattern
245
+ - `setBgColor(color)`, `setFgColor(color)`
246
+ - `setPattern(pattern)`
247
+
248
+ #### Borders
249
+ - `setBorder(style)`, `setBorderColor(color)`
250
+ - `setTop/Botton/Left/Right(style)`, `setTopColor/BottomColor/LeftColor/RightColor(color)`
251
+ - `setDiagonal(style)`, `setDiagonalColor(color)`
252
+
253
+ #### Protection
254
+ - `setLocked()`, `setUnlocked()`
255
+
256
+ #### Other
257
+ - `setHyperlink()`, `setFontOnly()`
258
+
259
+ #### Read Properties
260
+ - `getFontName()` - Get font name
261
+ - `getFontSize()` - Get font size
262
+ - `getFontColor()` - Get font color
263
+ - `getIsBold()` - Check if bold
264
+ - `getIsItalic()` - Check if italic
265
+ - `getNumFormat()` - Get number format
266
+ - `getBgColor()` - Get background color
267
+
268
+ ## Cell Types
269
+
270
+ When reading cells, the following types are returned:
271
+
272
+ - `empty` - Empty cell
273
+ - `string` - Text string
274
+ - `number` - Numeric value
275
+ - `boolean` - Boolean value
276
+ - `date` - Date/time value
277
+ - `error` - Error value
278
+ - `formula` - Formula
279
+ - `blank` - Blank cell
280
+
281
+ ## Constants
282
+
283
+ The library exports several useful constants:
284
+
285
+ - `Align` - Cell alignment values
286
+ - `VAlign` - Vertical alignment values
287
+ - `Border` - Border styles
288
+ - `Underline` - Underline styles
289
+ - `Script` - Superscript/subscript
290
+ - `Pattern` - Fill patterns
291
+ - `Paper` - Paper sizes
292
+ - `Gridlines` - Gridline options
293
+ - `Colors` - Common RGB colors
294
+ - `NumFormat` - Built-in number format indices
295
+ - `ImagePosition` - Image positioning options
296
+
297
+ ## Development
298
+
299
+ To regenerate the native specs after modifying the TypeScript spec files:
300
+
301
+ ```sh
302
+ npx nitrogen
303
+ ```
304
+
305
+ ## License
306
+
307
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
308
+
309
+ Third-party open source attributions are listed in the [NOTICE](NOTICE) file.
310
+
311
+ ## Acknowledgements
312
+
313
+ This library wraps the excellent [OpenXLSX](https://github.com/troldal/OpenXLSX) library, a modern C++ library for reading and writing Excel XLSX files.
314
+
315
+ ## Known Limitations
316
+
317
+ This library is based on OpenXLSX and inherits the following limitations:
318
+
319
+ ### Unsupported Formats
320
+
321
+ - **XLS format**: Only XLSX (Office Open XML) format is supported. Legacy XLS (Binary) format is not supported.
322
+
323
+ ### Unsupported Features
324
+
325
+ The following Excel features are not supported and will be ignored when reading or writing files:
326
+
327
+ - 🖼️ **Images**: Reading and writing images is not supported. Existing images in XLSX files will be ignored.
328
+ - 📊 **Charts**: Charts, graphs, and sparklines are not supported.
329
+ - ✏️ **Drawings/Shape**: Shapes, lines, arrows, and other drawing objects are not supported.
330
+ - 🔍 **Pivot Tables**: Pivot tables and pivot charts are not supported.
331
+ - 💻 **VBA/Macros**: VBA macros, forms, and ActiveX controls are not supported.
332
+ - 📋 **Comments**: Cell comments and notes are not supported.
333
+ - 📌 **Hyperlinks**: Only basic URL hyperlinks are supported.
334
+ - 🔄 **Conditional Formatting**: Conditional formatting rules are not supported.
335
+ - 📑 **Data Validation**: Data validation rules are not supported.
336
+
337
+ ### Notes
338
+
339
+ - When reading XLSX files that contain unsupported features, the library will still read the cell data and formatting, but unsupported elements will be silently ignored.
340
+ - When writing XLSX files, unsupported features cannot be added and will be omitted from the output.
@@ -0,0 +1,52 @@
1
+ cmake_minimum_required(VERSION 3.22.1)
2
+ project("NitroXlsx")
3
+
4
+ set(CMAKE_CXX_STANDARD 20)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+
7
+ set(OPENXLSX_DIR ${CMAKE_SOURCE_DIR}/../OpenXLSX)
8
+ if(NOT EXISTS ${OPENXLSX_DIR}/CMakeLists.txt)
9
+ include(FetchContent)
10
+ FetchContent_Declare(
11
+ OpenXLSX
12
+ GIT_REPOSITORY https://github.com/troldal/OpenXLSX.git
13
+ GIT_TAG v0.5.1
14
+ )
15
+ FetchContent_GetProperties(OpenXLSX)
16
+ if(NOT OpenXLSX_POPULATED)
17
+ FetchContent_Populate(OpenXLSX)
18
+ endif()
19
+ set(OPENXLSX_DIR ${openxlsx_SOURCE_DIR})
20
+ endif()
21
+
22
+ set(OPENXLSX_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
23
+ set(OPENXLSX_BUILD_TESTS OFF CACHE BOOL "" FORCE)
24
+ set(OPENXLSX_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
25
+ set(OPENXLSX_CREATE_DOCS OFF CACHE BOOL "" FORCE)
26
+ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
27
+
28
+ add_subdirectory(${OPENXLSX_DIR} OpenXLSX_build)
29
+
30
+ add_library(
31
+ NitroXlsx
32
+ SHARED
33
+ ../cpp/HybridNitroXlsx.cpp
34
+ ../cpp/HybridXlsxWorkbook.cpp
35
+ ../cpp/HybridXlsxWorksheet.cpp
36
+ ../cpp/HybridXlsxCellFormat.cpp
37
+ cpp-adapter.cpp
38
+ )
39
+
40
+ target_include_directories(
41
+ NitroXlsx
42
+ PRIVATE
43
+ ../cpp
44
+ ${OPENXLSX_DIR}
45
+ ${OPENXLSX_DIR}/OpenXLSX/headers
46
+ )
47
+
48
+ target_link_libraries(NitroXlsx OpenXLSX)
49
+
50
+ target_link_options(NitroXlsx PRIVATE -Wl,--unresolved-symbols=ignore-all)
51
+
52
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroXlsx+autolinking.cmake)
@@ -0,0 +1,49 @@
1
+ buildscript {
2
+ ext.safeExtGet = {prop, fallback ->
3
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4
+ }
5
+ }
6
+
7
+ apply plugin: 'com.android.library'
8
+ apply plugin: 'kotlin-android'
9
+
10
+ android {
11
+ namespace "com.margelo.nitro.xlsx"
12
+ compileSdk safeExtGet("compileSdkVersion", 34)
13
+
14
+ defaultConfig {
15
+ minSdk safeExtGet("minSdkVersion", 21)
16
+ externalNativeBuild {
17
+ cmake {
18
+ arguments "-DANDROID_STL=c++_shared"
19
+ }
20
+ }
21
+ }
22
+
23
+ buildFeatures {
24
+ buildConfig false
25
+ prefab true
26
+ }
27
+
28
+ compileOptions {
29
+ sourceCompatibility JavaVersion.VERSION_17
30
+ targetCompatibility JavaVersion.VERSION_17
31
+ }
32
+
33
+ kotlinOptions {
34
+ jvmTarget = "17"
35
+ }
36
+
37
+ externalNativeBuild {
38
+ cmake {
39
+ path file("CMakeLists.txt")
40
+ }
41
+ }
42
+ }
43
+
44
+ dependencies {
45
+ implementation "com.facebook.react:react-native:+"
46
+ implementation project(':react-native-nitro-modules')
47
+ }
48
+
49
+ apply from: "../nitrogen/generated/android/NitroXlsx+autolinking.gradle"
@@ -0,0 +1,9 @@
1
+ #include <jni.h>
2
+ #include <fbjni/fbjni.h>
3
+ #include "NitroXlsxOnLoad.hpp"
4
+
5
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
6
+ return facebook::jni::initialize(vm, []() {
7
+ margelo::nitro::xlsx::registerAllNatives();
8
+ });
9
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,22 @@
1
+ package com.margelo.nitro.xlsx
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class NitroXlsxPackage : ReactPackage {
9
+ companion object {
10
+ init {
11
+ NitroXlsxOnLoad.initializeNative()
12
+ }
13
+ }
14
+
15
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
16
+ return emptyList()
17
+ }
18
+
19
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
20
+ return emptyList()
21
+ }
22
+ }