18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
18 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.generationDoc;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.common.element.StyleSQLElement;
|
|
|
17 |
import org.openconcerto.openoffice.spreadsheet.Sheet;
|
|
|
18 |
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
|
|
|
19 |
|
|
|
20 |
import java.awt.Point;
|
|
|
21 |
import java.io.File;
|
|
|
22 |
import java.io.IOException;
|
|
|
23 |
import java.util.Map;
|
|
|
24 |
|
|
|
25 |
// TODO mettre les style dans des notes --> ex : @style : normal col1, Col2
|
|
|
26 |
// TODO popup si cell repeated > 50 ---> java heap space
|
|
|
27 |
// TODO popup si fichier introuvable
|
|
|
28 |
public class SpreadSheetGeneratorCompta extends SpreadSheetGenerator {
|
|
|
29 |
|
|
|
30 |
public SpreadSheetGeneratorCompta(SheetInterface sheet, String destFileName, boolean impr, boolean visu) {
|
|
|
31 |
this(sheet, destFileName, impr, visu, true);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public SpreadSheetGeneratorCompta(SheetInterface sheet, String destFileName, boolean impr, boolean visu, boolean exportPDF) {
|
|
|
35 |
super(sheet, destFileName, impr, visu, exportPDF);
|
|
|
36 |
new Thread(this).start();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
protected File generateWithStyle() throws IOException {
|
|
|
40 |
|
|
|
41 |
final SpreadSheet ssheet = loadTemplate();
|
|
|
42 |
if (ssheet == null) {
|
|
|
43 |
return null;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
final Map<String, Map<Integer, String>> mapStyleDef = StyleSQLElement.getMapAllStyle();
|
|
|
47 |
|
|
|
48 |
final Sheet sheet = ssheet.getSheet(0);
|
80 |
ilm |
49 |
|
18 |
ilm |
50 |
// on parcourt chaque ligne de la feuille pour recuperer les styles
|
|
|
51 |
String s = (sheet.getPrintRanges() == null) ? "" : sheet.getPrintRanges().toString();
|
|
|
52 |
String[] range = s.split(":");
|
|
|
53 |
|
|
|
54 |
for (int i = 0; i < range.length; i++) {
|
|
|
55 |
String string = range[i];
|
|
|
56 |
range[i] = string.subSequence(string.indexOf('.') + 1, string.length()).toString();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// int colDeb = -1;
|
|
|
60 |
int colEnd = -1;
|
|
|
61 |
int rowEnd = -1;
|
|
|
62 |
if (range.length > 1) {
|
|
|
63 |
// colDeb = sheet.resolveHint(range[0]).x;
|
|
|
64 |
final Point resolveHint = sheet.resolveHint(range[1]);
|
|
|
65 |
colEnd = resolveHint.x;
|
|
|
66 |
rowEnd = resolveHint.y;
|
|
|
67 |
}
|
|
|
68 |
searchStyle(sheet, mapStyleDef, colEnd, rowEnd);
|
|
|
69 |
|
|
|
70 |
if (colEnd > 0) {
|
|
|
71 |
System.err.println("Set Column Count to :: " + (colEnd + 1));
|
|
|
72 |
sheet.setColumnCount(colEnd + 1);
|
|
|
73 |
}
|
182 |
ilm |
74 |
if (this.nbPage < 1) {
|
|
|
75 |
throw new IllegalArgumentException("invalid page count : " + this.nbPage);
|
|
|
76 |
}
|
|
|
77 |
sheet.duplicateFirstRows(this.nbRowsPerPage, this.nbPage - 1);
|
80 |
ilm |
78 |
|
18 |
ilm |
79 |
Object printRangeObj = sheet.getPrintRanges();
|
|
|
80 |
if (printRangeObj != null) {
|
|
|
81 |
String[] range2 = printRangeObj.toString().split(":");
|
|
|
82 |
|
|
|
83 |
for (int i = 0; i < range2.length; i++) {
|
|
|
84 |
String string = range2[i];
|
|
|
85 |
range2[i] = string.subSequence(string.indexOf('.') + 1, string.length()).toString();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if (range2.length > 1) {
|
182 |
ilm |
89 |
int end = sheet.resolveHint(range2[1]).y + 1;
|
|
|
90 |
int rowEndNew = end * this.nbPage;
|
18 |
ilm |
91 |
String sNew = s.replaceAll(String.valueOf(end), String.valueOf(rowEndNew));
|
|
|
92 |
sheet.setPrintRanges(sNew);
|
182 |
ilm |
93 |
System.err.println("SpreadSheetGenerator ****** Replace print ranges; Old:" + end + "--" + s + " New:" + rowEndNew + "--" + sNew);
|
18 |
ilm |
94 |
}
|
|
|
95 |
} else {
|
|
|
96 |
sheet.removePrintRanges();
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
// on place les valeurs
|
|
|
100 |
fill(sheet, mapStyleDef);
|
|
|
101 |
|
|
|
102 |
return save(ssheet);
|
|
|
103 |
}
|
|
|
104 |
}
|