sheetra 1.0.1 → 1.0.3

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.
package/README.md CHANGED
@@ -4,29 +4,170 @@
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/sheetra.svg)](https://www.npmjs.com/package/sheetra)
6
6
  [![License](https://img.shields.io/github/license/opencorex-org/sheetra)](LICENSE)
7
+ [![Build Status](https://github.com/opencorex-org/sheetra/actions/workflows/build.yml/badge.svg)](https://github.com/opencorex-org/sheetra/actions)
7
8
  [![npm downloads](https://img.shields.io/npm/dm/sheetra.svg)](https://www.npmjs.com/package/sheetra)
8
9
  [![GitHub stars](https://img.shields.io/github/stars/opencorex-org/sheetra?style=social)](https://github.com/opencorex-org/sheetra)
9
10
  [![GitHub issues](https://img.shields.io/github/issues/opencorex-org/sheetra)](https://github.com/opencorex-org/sheetra/issues)
10
- [![Version](https://img.shields.io/badge/version-1.0.0-blue)](https://github.com/opencorex-org/sheetra/releases)
11
11
 
12
12
  Sheetra is a powerful, zero-dependency library for exporting data to Excel (XLSX), CSV, and JSON formats. It provides a clean, fluent API for creating complex spreadsheets with styles, outlines, and sections.
13
13
 
14
- ## Features
14
+ ---
15
15
 
16
- - **Zero Dependencies** – Pure TypeScript/JavaScript implementation
17
- - **Multiple Formats** – Export to XLSX, CSV, JSON
18
- - **Styling Support** – Bold, colors, borders, alignment
19
- - **Outlines & Groups** – Create collapsible sections
20
- - **Fluent API** Chain methods for easy construction
21
- - **TypeScript** – Full type support
22
- - **Browser & Node** Works in both environments
16
+
17
+ ## Example Usage
18
+
19
+ ```ts
20
+ import { ExportBuilder, StyleBuilder } from 'sheetra';
21
+
22
+ // --- Comprehensive Example: All Features ---
23
+ const users = [
24
+ { name: 'John Doe', age: 30, email: 'john@example.com', department: 'Engineering' },
25
+ { name: 'Jane Smith', age: 25, email: 'jane@example.com', department: 'Marketing' },
26
+ ];
27
+ const parts = [
28
+ { part_number: 'P001', part_name: 'Widget', current_stock: 100, price: 29.99 },
29
+ { part_number: 'P002', part_name: 'Gadget', current_stock: 50, price: 49.99 },
30
+ ];
31
+ const salesData = [
32
+ { product: 'Widget', jan: 1500, feb: 1800, mar: 2100 },
33
+ { product: 'Gadget', jan: 900, feb: 1100, mar: 1300 },
34
+ ];
35
+
36
+ // Styled header
37
+ const headerStyle = StyleBuilder.create()
38
+ .bold()
39
+ .backgroundColor('#4F81BD')
40
+ .color('#FFFFFF')
41
+ .align('center')
42
+ .build();
43
+
44
+ ExportBuilder.create('All Features Demo')
45
+ // Set column widths
46
+ .setColumnWidths([150, 100, 200, 120])
47
+ // Add styled header row
48
+ .addHeaderRow(['Name', 'Age', 'Email', 'Department'], headerStyle)
49
+ // Add data rows
50
+ .addDataRows(users.map(u => [u.name, u.age, u.email, u.department]))
51
+ // Add section
52
+ .addSection({ name: 'Parts', title: 'Parts Inventory' })
53
+ .addHeaderRow(['Part Number', 'Part Name', 'Stock', 'Price'])
54
+ .addDataRows(parts.map(p => [p.part_number, p.part_name, p.current_stock, p.price]))
55
+ // Merge cells for a title
56
+ .addDataRows([['Monthly Sales Report', '', '', '']])
57
+ .mergeCells(7, 0, 7, 3)
58
+ .setAlignment(7, 0, 'center')
59
+ // Alignment demo
60
+ .addHeaderRow(['Left', 'Center', 'Right'])
61
+ .setAlignment(8, 0, 'left')
62
+ .setAlignment(8, 1, 'center')
63
+ .setAlignment(8, 2, 'right')
64
+ .addDataRows([
65
+ ['Left Text', 'Center Text', 'Right Text'],
66
+ ['Value 1', 'Value 2', 'Value 3'],
67
+ ])
68
+ .setRangeAlignment(9, 0, 10, 0, 'left')
69
+ .setRangeAlignment(9, 1, 10, 1, 'center')
70
+ .setRangeAlignment(9, 2, 10, 2, 'right')
71
+ // Auto-size columns
72
+ .autoSizeColumns()
73
+ // Download as XLSX
74
+ .download({ filename: 'all-features-demo.xlsx', format: 'xlsx' });
75
+ ```
76
+
77
+ This example demonstrates:
78
+ - Column widths and auto-sizing
79
+ - Merged cells for titles
80
+ - Alignment (left, center, right, range)
81
+ - Sections and headers
82
+ - Styled headers with StyleBuilder
83
+ - Data rows and multiple tables
84
+ - XLSX export
85
+
86
+ See the [sheetra-demo](./sheetra-demo/src/App.tsx) for a full-featured React demo with all features in action.
87
+ .addDataRows(users.map(u => [u.name, u.age, u.email, u.department]))
88
+ .download({ filename: 'styled-report.xlsx', format: 'xlsx' });
89
+ ```
90
+
91
+ ## Troubleshooting
92
+
93
+ **Upgrading from previous versions?**
94
+
95
+ If you previously encountered errors with styled exports (e.g., `SyntaxError: Expected ':' after property name in JSON`), upgrade to the latest version. Style and alignment handling is now robust and all edge cases are supported.
96
+
97
+
98
+ ---
23
99
 
24
100
  ## Installation
25
101
 
102
+ Install Sheetra using your favorite package manager:
103
+
26
104
  ```bash
27
105
  npm install sheetra
28
106
  # or
29
107
  yarn add sheetra
30
108
  # or
31
109
  pnpm add sheetra
32
- ```
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Usage
115
+
116
+ ### Basic Example
117
+
118
+ ```typescript
119
+ import { ExportBuilder } from 'sheetra';
120
+
121
+ const builder = ExportBuilder.create('Users')
122
+ .addHeaderRow(['Name', 'Age'])
123
+ .addDataRows([
124
+ ['John', 30],
125
+ ['Jane', 25]
126
+ ]);
127
+
128
+ builder.download({ filename: 'users.xlsx', format: 'xlsx' });
129
+ ```
130
+
131
+ ### Advanced Example
132
+
133
+ ```typescript
134
+ import { ExportBuilder } from 'sheetra';
135
+
136
+ const parts = [
137
+ { part_number: 'P001', part_name: 'Widget', current_stock: 100 },
138
+ { part_number: 'P002', part_name: 'Gadget', current_stock: 50 },
139
+ ];
140
+
141
+ const instances = [
142
+ { serial_number: 'S001', part_number: 'P001', status: 'Active', location: 'A1' },
143
+ { serial_number: 'S002', part_number: 'P001', status: 'Inactive', location: 'A2' },
144
+ { serial_number: 'S003', part_number: 'P002', status: 'Active', location: 'B1' },
145
+ ];
146
+
147
+ ExportBuilder.create('Inventory')
148
+ .addSection({ name: 'Parts' })
149
+ .addHeaderRow(['Part Number', 'Part Name', 'Current Stock'])
150
+ .addDataRows(parts.map(p => [p.part_number, p.part_name, p.current_stock]))
151
+ .addSection({ name: 'Instances' })
152
+ .addHeaderRow(['Serial Number', 'Part Number', 'Status', 'Location'])
153
+ .addDataRows(instances.map(i => [i.serial_number, i.part_number, i.status, i.location]))
154
+ .download({ filename: 'inventory.xlsx', format: 'xlsx' });
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Documentation
160
+
161
+ For detailed documentation, visit the [API Reference](docs/API.md) and [Getting Started Guide](docs/GETTING_STARTED.md).
162
+
163
+ ---
164
+
165
+ ## Contributing
166
+
167
+ We welcome contributions! Please read the [Contributing Guide](docs/CONTRIBUTING.md) to learn how you can help improve Sheetra.
168
+
169
+ ---
170
+
171
+ ## License
172
+
173
+ This project is licensed under the [Apache 2.0 License](LICENSE).