pyfastexcel 0.0.4__tar.gz → 0.0.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyfastexcel
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: High performace excel file generation library.
5
5
  Home-page: https://github.com/Zncl2222/pyfastexcel
6
6
  Author: Zncl2222
@@ -20,7 +20,7 @@ Requires-Python: >=3.7
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: msgspec
23
- Requires-Dist: openpyxl-style-writer
23
+ Requires-Dist: openpyxl-style-writer>=1.1.3
24
24
 
25
25
  # pyfastexcel
26
26
 
@@ -108,11 +108,54 @@ high performance.
108
108
 
109
109
  ## Usage
110
110
 
111
- The current version can only be used with this library through example
112
- snippets or the example.py file in the root directory of this repository.
113
- See [limitations](#current-limitations--future-plans) for more details.
111
+ The index assignment is now avaliable in `Workbook` and the `FastWriter`.
112
+ Here is the example usage:
114
113
 
115
- The steps are:
114
+ ```python
115
+ from pyfastexcel import Workbook
116
+ from pyfastexcel.utils import set_custom_style
117
+
118
+ # CustomStyle will be integrate to the pyfatexcel in next version
119
+ # Beside, CustomStyle will be re-implement in future to make it no-longer
120
+ # depend on openpyxl_style writer and openpyxl
121
+ from openpyxl_style_writer import CustomStyle
122
+
123
+
124
+ if __name__ == '__main__':
125
+ # Workbook
126
+ wb = Workbook()
127
+
128
+ # Set and register CustomStyle
129
+ bold_style = CustomStyle(font_size=15, font_bold=True)
130
+ set_custom_style('bold_style', bold_style)
131
+
132
+ ws = wb['Sheet1']
133
+ # Write value with default style
134
+ ws['A1'] = 'A1 value'
135
+ # Write value with custom style
136
+ ws['B1'] = ('B1 value', 'bold_style')
137
+
138
+ # Write value in slice with default style
139
+ ws['A2': 'C2'] = [1, 2, 3]
140
+ # Write value in slice with custom style
141
+ ws['A3': 'C3'] = [(1, 'bold_style'), (2, 'bold_style'), (3, 'bold_style')]
142
+
143
+ # Write value by row with default style (python index 0 is the index 1 in excel)
144
+ ws[3] = [9, 8, 'go']
145
+ # Write value by row with custom style
146
+ ws[4] = [(9, 'bold_style'), (8, 'bold_style'), ('go', 'bold_style')]
147
+
148
+ # Send request to golang lib and create excel
149
+ wb.read_lib_and_create_excel()
150
+
151
+ # File path to save
152
+ file_path = 'pyexample_workbook.xlsx'
153
+ wb.save(file_path)
154
+
155
+ ```
156
+
157
+ You can also using the `FastWriter` or `NormalWriter` which was the
158
+ subclass of `Workbook` to write excel row by row, see the following steps:
116
159
 
117
160
  1. Create a class for your `style` registed like `StyleCollections`
118
161
  in the example.
@@ -190,7 +233,7 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
190
233
  self.set_file_props('Creator', 'Hello')
191
234
  self._create_single_header()
192
235
  self._create_body()
193
- return self._read_lib_and_create_excel()
236
+ return self.read_lib_and_create_excel()
194
237
 
195
238
  def _set_header(self):
196
239
  self.headers = list(self.data[0].keys())
@@ -218,64 +261,40 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
218
261
  self.row_append(row[h], style='black_fill_style')
219
262
  self.create_row()
220
263
 
221
-
222
264
  if __name__ == '__main__':
223
265
  data = prepare_example_data(653, 90)
224
- excel_normal = PyExcelizeNormalExample(data).create_excel()
266
+ normal_writer = PyExcelizeFastExample(data)
267
+ excel_normal = normal_writer.create_excel()
225
268
  file_path = 'pyexample_normal.xlsx'
226
- with open(file_path2, 'wb') as file:
227
- file.write(excel_normal)
269
+ normal_writer.save('pyexample_normal.xlsx')
228
270
  ```
229
271
 
230
- ## Current Limitations & Future Plans
272
+ The example of FastWriter now supports index assignment. Please see
273
+ the last few lines of code in `_create_body()` for reference.
231
274
 
232
- ### Problem 1: Dependence on Other Excel Package
233
-
234
- Limitations:
235
-
236
- This project currently depends on the `CustomStyle`` object of
237
- the [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer)
238
- package, which is built for openpyxl to write styles in write-only
239
- mode more efficiently without duplicating code.
240
-
241
- Future Plans:
242
-
243
- This project plans to create its own `Style` object, making it no longer
244
- dependent on the mentioned package.
275
+ ```python
276
+ from pyfastexcel.driver import FastWriter
245
277
 
246
- ### Problem 2: Inflexible Usage
247
278
 
248
- Limitations:
279
+ class PyExcelizeFastExample(FastWriter, StyleCollections):
249
280
 
250
- The current version only has the function to write a cell with a style using
251
- the class-based inheritance streaming writer method, similar to the
252
- `Advanced Usage` in
253
- [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer).
254
- This means users must inherit the `NormalWriter` or `FastWriter` classes and
255
- also your `StyleCollections` to correctly register and use the Style. In short,
256
- if you want to use this library, you have to create `StyleCollections` and
257
- `Your-Writer-Class` and implement the excel creation in `Your-Writer-Class` as
258
- shown in the code snippet provided.
259
-
260
- ```python
261
- from openpyxl_style_writer import CustomStyle
262
-
263
- class StyleCollections:
264
- black_fill_style = CustomStyle(
265
- font_size='11',
266
- font_bold=True,
267
- font_color='F62B00',
268
- fill_color='000000',
269
- )
270
- test_fill_style = CustomStyle(
271
- font_size='19'
272
- )
281
+ def create_excel(self) -> bytes:
282
+ self._set_header()
283
+ self._create_style()
284
+ self.set_file_props('Creator', 'Hello')
285
+ self._create_single_header()
286
+ self._create_body()
287
+ return self.read_lib_and_create_excel()
273
288
 
289
+ def _set_header(self):
290
+ self.headers = list(self.data[0].keys())
274
291
 
275
- class PyExcelizeNormalExample(NormalWriter, StyleCollections):
276
- headers = ['col1', 'col2', 'col3']
292
+ def _create_single_header(self):
293
+ for h in self.headers:
294
+ self.row_append(h, style='green_fill_style')
295
+ self.create_row()
277
296
 
278
- def create_excel(self) -> None:
297
+ def _create_body(self) -> None:
279
298
  for row in self.data:
280
299
  for h in self.headers:
281
300
  if h[-1] in ('1', '3', '5', '7', '9'):
@@ -284,25 +303,44 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
284
303
  self.row_append(row[h], style='test_fill_style')
285
304
  self.create_row()
286
305
 
306
+ self.switch_sheet('Sheet2')
307
+ for row in self.data:
308
+ for h in self.headers:
309
+ if h[-1] in ('1', '3', '5', '7', '9'):
310
+ self.row_append(row[h], style=self.green_fill_style)
311
+ else:
312
+ self.row_append(row[h], style='black_fill_style')
313
+ self.create_row()
314
+
315
+ # Assigning a value with a specific style
316
+ self.workbook['Sheet1']['A2'] = ('Hellow World', 'black_fill_style')
317
+
318
+ # Assigning a value without specifying a style (default style used)
319
+ self.workbook['Sheet1']['A3'] = 'I am A3'
320
+ self.workbook['Sheet1']['AB9'] = 'GOGOGO'
321
+
322
+
287
323
  if __name__ == '__main__':
288
- data = [{'col1': 1, 'col2': 2, 'col3': 3}, {'col1': 4, 'col2': 5, 'col3', 6}]
289
- excel = PyExcelizeNormalExample(data).create_excel()
290
- with open('example.xlsx', 'wb') as file:
291
- file.write(excel)
324
+ data = prepare_example_data(653, 90)
325
+ normal_writer = PyExcelizeFastExample(data)
326
+ excel_normal = normal_writer.create_excel()
327
+ file_path = 'pyexample_normal.xlsx'
328
+ normal_writer.save('pyexample_normal.xlsx')
329
+
292
330
  ```
293
331
 
294
- Future Plans:
332
+ ## Current Limitations & Future Plans
295
333
 
296
- 1. Make the style register in the shared class object on the Python side.
297
- Also, create a function to register the style. By doing so, the style
298
- won't need to depend on the `custom-writer-class`. All the styles registered
299
- through that function will be sent to Golang and registered.
334
+ ### Problem 1: Dependence on Other Excel Package
300
335
 
301
- 2. Add the ability to create a cell and style with the index, similar
302
- to what openpyxl does. (The code snippet provided is only an example,
303
- not the real implementation method planned)
336
+ Limitations:
304
337
 
305
- ```python
306
- ws['A1'].value = 'test'
307
- ws['A1'].style = 'black_fill_style'
308
- ```
338
+ This project currently depends on the `CustomStyle` object of
339
+ the [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer)
340
+ package, which is built for openpyxl to write styles in write-only
341
+ mode more efficiently without duplicating code.
342
+
343
+ Future Plans:
344
+
345
+ This project plans to create its own `Style` object, making it no longer
346
+ dependent on the mentioned package.
@@ -84,11 +84,54 @@ high performance.
84
84
 
85
85
  ## Usage
86
86
 
87
- The current version can only be used with this library through example
88
- snippets or the example.py file in the root directory of this repository.
89
- See [limitations](#current-limitations--future-plans) for more details.
87
+ The index assignment is now avaliable in `Workbook` and the `FastWriter`.
88
+ Here is the example usage:
90
89
 
91
- The steps are:
90
+ ```python
91
+ from pyfastexcel import Workbook
92
+ from pyfastexcel.utils import set_custom_style
93
+
94
+ # CustomStyle will be integrate to the pyfatexcel in next version
95
+ # Beside, CustomStyle will be re-implement in future to make it no-longer
96
+ # depend on openpyxl_style writer and openpyxl
97
+ from openpyxl_style_writer import CustomStyle
98
+
99
+
100
+ if __name__ == '__main__':
101
+ # Workbook
102
+ wb = Workbook()
103
+
104
+ # Set and register CustomStyle
105
+ bold_style = CustomStyle(font_size=15, font_bold=True)
106
+ set_custom_style('bold_style', bold_style)
107
+
108
+ ws = wb['Sheet1']
109
+ # Write value with default style
110
+ ws['A1'] = 'A1 value'
111
+ # Write value with custom style
112
+ ws['B1'] = ('B1 value', 'bold_style')
113
+
114
+ # Write value in slice with default style
115
+ ws['A2': 'C2'] = [1, 2, 3]
116
+ # Write value in slice with custom style
117
+ ws['A3': 'C3'] = [(1, 'bold_style'), (2, 'bold_style'), (3, 'bold_style')]
118
+
119
+ # Write value by row with default style (python index 0 is the index 1 in excel)
120
+ ws[3] = [9, 8, 'go']
121
+ # Write value by row with custom style
122
+ ws[4] = [(9, 'bold_style'), (8, 'bold_style'), ('go', 'bold_style')]
123
+
124
+ # Send request to golang lib and create excel
125
+ wb.read_lib_and_create_excel()
126
+
127
+ # File path to save
128
+ file_path = 'pyexample_workbook.xlsx'
129
+ wb.save(file_path)
130
+
131
+ ```
132
+
133
+ You can also using the `FastWriter` or `NormalWriter` which was the
134
+ subclass of `Workbook` to write excel row by row, see the following steps:
92
135
 
93
136
  1. Create a class for your `style` registed like `StyleCollections`
94
137
  in the example.
@@ -166,7 +209,7 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
166
209
  self.set_file_props('Creator', 'Hello')
167
210
  self._create_single_header()
168
211
  self._create_body()
169
- return self._read_lib_and_create_excel()
212
+ return self.read_lib_and_create_excel()
170
213
 
171
214
  def _set_header(self):
172
215
  self.headers = list(self.data[0].keys())
@@ -194,64 +237,40 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
194
237
  self.row_append(row[h], style='black_fill_style')
195
238
  self.create_row()
196
239
 
197
-
198
240
  if __name__ == '__main__':
199
241
  data = prepare_example_data(653, 90)
200
- excel_normal = PyExcelizeNormalExample(data).create_excel()
242
+ normal_writer = PyExcelizeFastExample(data)
243
+ excel_normal = normal_writer.create_excel()
201
244
  file_path = 'pyexample_normal.xlsx'
202
- with open(file_path2, 'wb') as file:
203
- file.write(excel_normal)
245
+ normal_writer.save('pyexample_normal.xlsx')
204
246
  ```
205
247
 
206
- ## Current Limitations & Future Plans
248
+ The example of FastWriter now supports index assignment. Please see
249
+ the last few lines of code in `_create_body()` for reference.
207
250
 
208
- ### Problem 1: Dependence on Other Excel Package
209
-
210
- Limitations:
211
-
212
- This project currently depends on the `CustomStyle`` object of
213
- the [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer)
214
- package, which is built for openpyxl to write styles in write-only
215
- mode more efficiently without duplicating code.
216
-
217
- Future Plans:
218
-
219
- This project plans to create its own `Style` object, making it no longer
220
- dependent on the mentioned package.
251
+ ```python
252
+ from pyfastexcel.driver import FastWriter
221
253
 
222
- ### Problem 2: Inflexible Usage
223
254
 
224
- Limitations:
255
+ class PyExcelizeFastExample(FastWriter, StyleCollections):
225
256
 
226
- The current version only has the function to write a cell with a style using
227
- the class-based inheritance streaming writer method, similar to the
228
- `Advanced Usage` in
229
- [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer).
230
- This means users must inherit the `NormalWriter` or `FastWriter` classes and
231
- also your `StyleCollections` to correctly register and use the Style. In short,
232
- if you want to use this library, you have to create `StyleCollections` and
233
- `Your-Writer-Class` and implement the excel creation in `Your-Writer-Class` as
234
- shown in the code snippet provided.
235
-
236
- ```python
237
- from openpyxl_style_writer import CustomStyle
238
-
239
- class StyleCollections:
240
- black_fill_style = CustomStyle(
241
- font_size='11',
242
- font_bold=True,
243
- font_color='F62B00',
244
- fill_color='000000',
245
- )
246
- test_fill_style = CustomStyle(
247
- font_size='19'
248
- )
257
+ def create_excel(self) -> bytes:
258
+ self._set_header()
259
+ self._create_style()
260
+ self.set_file_props('Creator', 'Hello')
261
+ self._create_single_header()
262
+ self._create_body()
263
+ return self.read_lib_and_create_excel()
249
264
 
265
+ def _set_header(self):
266
+ self.headers = list(self.data[0].keys())
250
267
 
251
- class PyExcelizeNormalExample(NormalWriter, StyleCollections):
252
- headers = ['col1', 'col2', 'col3']
268
+ def _create_single_header(self):
269
+ for h in self.headers:
270
+ self.row_append(h, style='green_fill_style')
271
+ self.create_row()
253
272
 
254
- def create_excel(self) -> None:
273
+ def _create_body(self) -> None:
255
274
  for row in self.data:
256
275
  for h in self.headers:
257
276
  if h[-1] in ('1', '3', '5', '7', '9'):
@@ -260,25 +279,44 @@ class PyExcelizeNormalExample(NormalWriter, StyleCollections):
260
279
  self.row_append(row[h], style='test_fill_style')
261
280
  self.create_row()
262
281
 
282
+ self.switch_sheet('Sheet2')
283
+ for row in self.data:
284
+ for h in self.headers:
285
+ if h[-1] in ('1', '3', '5', '7', '9'):
286
+ self.row_append(row[h], style=self.green_fill_style)
287
+ else:
288
+ self.row_append(row[h], style='black_fill_style')
289
+ self.create_row()
290
+
291
+ # Assigning a value with a specific style
292
+ self.workbook['Sheet1']['A2'] = ('Hellow World', 'black_fill_style')
293
+
294
+ # Assigning a value without specifying a style (default style used)
295
+ self.workbook['Sheet1']['A3'] = 'I am A3'
296
+ self.workbook['Sheet1']['AB9'] = 'GOGOGO'
297
+
298
+
263
299
  if __name__ == '__main__':
264
- data = [{'col1': 1, 'col2': 2, 'col3': 3}, {'col1': 4, 'col2': 5, 'col3', 6}]
265
- excel = PyExcelizeNormalExample(data).create_excel()
266
- with open('example.xlsx', 'wb') as file:
267
- file.write(excel)
300
+ data = prepare_example_data(653, 90)
301
+ normal_writer = PyExcelizeFastExample(data)
302
+ excel_normal = normal_writer.create_excel()
303
+ file_path = 'pyexample_normal.xlsx'
304
+ normal_writer.save('pyexample_normal.xlsx')
305
+
268
306
  ```
269
307
 
270
- Future Plans:
308
+ ## Current Limitations & Future Plans
271
309
 
272
- 1. Make the style register in the shared class object on the Python side.
273
- Also, create a function to register the style. By doing so, the style
274
- won't need to depend on the `custom-writer-class`. All the styles registered
275
- through that function will be sent to Golang and registered.
310
+ ### Problem 1: Dependence on Other Excel Package
276
311
 
277
- 2. Add the ability to create a cell and style with the index, similar
278
- to what openpyxl does. (The code snippet provided is only an example,
279
- not the real implementation method planned)
312
+ Limitations:
280
313
 
281
- ```python
282
- ws['A1'].value = 'test'
283
- ws['A1'].style = 'black_fill_style'
284
- ```
314
+ This project currently depends on the `CustomStyle` object of
315
+ the [openpyxl_style_writer](https://github.com/Zncl2222/openpyxl_style_writer)
316
+ package, which is built for openpyxl to write styles in write-only
317
+ mode more efficiently without duplicating code.
318
+
319
+ Future Plans:
320
+
321
+ This project plans to create its own `Style` object, making it no longer
322
+ dependent on the mentioned package.
@@ -0,0 +1,7 @@
1
+ from pyfastexcel.writer import FastWriter, NormalWriter, Workbook
2
+
3
+ __all__ = [
4
+ 'Workbook',
5
+ 'FastWriter',
6
+ 'NormalWriter',
7
+ ]