Révision 964
| tmp/org.txm.libs.msoffice/.project (revision 964) | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
| 2 |
<projectDescription> |
|
| 3 |
<name>org.txm.libs.msoffice</name> |
|
| 4 |
<comment></comment> |
|
| 5 |
<projects> |
|
| 6 |
</projects> |
|
| 7 |
<buildSpec> |
|
| 8 |
<buildCommand> |
|
| 9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
| 10 |
<arguments> |
|
| 11 |
</arguments> |
|
| 12 |
</buildCommand> |
|
| 13 |
<buildCommand> |
|
| 14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
| 15 |
<arguments> |
|
| 16 |
</arguments> |
|
| 17 |
</buildCommand> |
|
| 18 |
<buildCommand> |
|
| 19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
| 20 |
<arguments> |
|
| 21 |
</arguments> |
|
| 22 |
</buildCommand> |
|
| 23 |
</buildSpec> |
|
| 24 |
<natures> |
|
| 25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
| 26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
| 27 |
</natures> |
|
| 28 |
</projectDescription> |
|
| 0 | 29 | |
| tmp/org.txm.libs.msoffice/src/org/txm/libs/msoffice/ReadExcel.java (revision 964) | ||
|---|---|---|
| 1 |
package org.txm.libs.msoffice; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.util.ArrayList; |
|
| 5 |
|
|
| 6 |
import org.apache.poi.ss.usermodel.Cell; |
|
| 7 |
import org.apache.poi.ss.usermodel.Row; |
|
| 8 |
import org.apache.poi.ss.usermodel.Sheet; |
|
| 9 |
import org.apache.poi.ss.usermodel.Workbook; |
|
| 10 |
import org.apache.poi.ss.usermodel.WorkbookFactory; |
|
| 11 |
|
|
| 12 |
public class ReadExcel {
|
|
| 13 |
|
|
| 14 |
public static ArrayList<ArrayList<String>> toTable(File inputFile, String sheetName) {
|
|
| 15 |
|
|
| 16 |
ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>(); |
|
| 17 |
|
|
| 18 |
if (!inputFile.canRead()) {
|
|
| 19 |
System.out.println("** Excel2XML: '"+inputFile.getName()+"' file not readable. Aborting.");
|
|
| 20 |
return data; |
|
| 21 |
} |
|
| 22 |
|
|
| 23 |
try {
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
Workbook wb = WorkbookFactory.create(inputFile); |
|
| 27 |
Sheet ws; |
|
| 28 |
if (sheetName == null || sheetName.length() == 0) {
|
|
| 29 |
ws = wb.getSheetAt(0); |
|
| 30 |
} else {
|
|
| 31 |
ws = wb.getSheet(sheetName); |
|
| 32 |
if (ws == null) {
|
|
| 33 |
ws = wb.getSheetAt(0); |
|
| 34 |
} |
|
| 35 |
} |
|
| 36 |
|
|
| 37 |
if (ws == null) {
|
|
| 38 |
System.out.println("** Excel2XML: no sheet found. Aborting.");
|
|
| 39 |
return data; |
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
int nRows = ws.getPhysicalNumberOfRows(); |
|
| 43 |
if (nRows == 0) return null; |
|
| 44 |
|
|
| 45 |
Row firstRow = ws.getRow(0); |
|
| 46 |
int colMax = firstRow.getLastCellNum(); |
|
| 47 |
|
|
| 48 |
ArrayList<String> headers = new ArrayList<String>(); |
|
| 49 |
for (int it = 0 ; it < colMax; it++) {
|
|
| 50 |
headers.add(firstRow.getCell(it).getStringCellValue().replaceAll("\n", ";"));
|
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
for (int rowIndex = 0 ; rowIndex < nRows ; rowIndex++) {
|
|
| 54 |
Row row = ws.getRow(rowIndex); |
|
| 55 |
ArrayList<String> dataLine = new ArrayList<String>(); |
|
| 56 |
data.add(dataLine); |
|
| 57 |
for (int colIndex = 0 ; colIndex < colMax ; colIndex++) {
|
|
| 58 |
Cell cell = row.getCell(colIndex); |
|
| 59 |
if (cell != null) {
|
|
| 60 |
String value = cell.getStringCellValue().replaceAll("\n", ";").trim();
|
|
| 61 |
dataLine.add(value); |
|
| 62 |
} else {
|
|
| 63 |
dataLine.add("");
|
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
} catch (Exception e) {
|
|
| 69 |
System.out.println("** Excel2XML: unable to read input file. Aborting.");
|
|
| 70 |
System.out.println( e.getLocalizedMessage()); |
|
| 71 |
e.printStackTrace(); |
|
| 72 |
return null; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
return data; |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
public static void main(String[] args) {
|
|
| 79 |
ArrayList<ArrayList<String>> data = toTable(new File("/home/mdecorde/xml/metadata.xlsx"), null);
|
|
| 80 |
if (data.size() == 0) {
|
|
| 81 |
System.out.println("no data.");
|
|
| 82 |
} else {
|
|
| 83 |
System.out.println(data); |
|
| 84 |
} |
|
| 85 |
} |
|
| 86 |
} |
|
| 0 | 87 | |
| tmp/org.txm.libs.msoffice/build.properties (revision 964) | ||
|---|---|---|
| 1 |
source.. = src/ |
|
| 2 |
output.. = bin/ |
|
| 3 |
bin.includes = META-INF/,\ |
|
| 4 |
. |
|
| 0 | 5 | |
| tmp/org.txm.libs.msoffice/.settings/org.eclipse.jdt.core.prefs (revision 964) | ||
|---|---|---|
| 1 |
eclipse.preferences.version=1 |
|
| 2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
| 3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
|
| 4 |
org.eclipse.jdt.core.compiler.compliance=1.8 |
|
| 5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
| 6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
| 7 |
org.eclipse.jdt.core.compiler.source=1.8 |
|
| 0 | 8 | |
| tmp/org.txm.libs.msoffice/.classpath (revision 964) | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
| 2 |
<classpath> |
|
| 3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
|
| 4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
| 5 |
<classpathentry kind="src" path="src"/> |
|
| 6 |
<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.10.jar"/> |
|
| 7 |
<classpathentry exported="true" kind="lib" path="lib/commons-collections4-4.1.jar"/> |
|
| 8 |
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/> |
|
| 9 |
<classpathentry exported="true" kind="lib" path="lib/curvesapi-1.04.jar"/> |
|
| 10 |
<classpathentry exported="true" kind="lib" path="lib/junit-4.12.jar"/> |
|
| 11 |
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/> |
|
| 12 |
<classpathentry exported="true" kind="lib" path="lib/ooxml-schemas-1.3.jar"/> |
|
| 13 |
<classpathentry exported="true" kind="lib" path="lib/poi-3.17.jar"/> |
|
| 14 |
<classpathentry exported="true" kind="lib" path="lib/poi-excelant-3.17.jar"/> |
|
| 15 |
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-3.17.jar"/> |
|
| 16 |
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-schemas-3.17.jar"/> |
|
| 17 |
<classpathentry exported="true" kind="lib" path="lib/poi-scratchpad-3.17.jar"/> |
|
| 18 |
<classpathentry exported="true" kind="lib" path="lib/xmlbeans-2.6.0.jar"/> |
|
| 19 |
<classpathentry kind="output" path="bin"/> |
|
| 20 |
</classpath> |
|
| 0 | 21 | |
| tmp/org.txm.libs.msoffice/META-INF/MANIFEST.MF (revision 964) | ||
|---|---|---|
| 1 |
Manifest-Version: 1.0 |
|
| 2 |
Bundle-ManifestVersion: 2 |
|
| 3 |
Bundle-Name: org.txm.libs.msoffice |
|
| 4 |
Bundle-SymbolicName: org.txm.libs.msoffice |
|
| 5 |
Bundle-Version: 1.0.0.qualifier |
|
| 6 |
Automatic-Module-Name: org.txm.libs.msoffice |
|
| 7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
|
| 0 | 8 | |
| tmp/org.txm.libs.office/.project (revision 964) | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
| 2 |
<projectDescription> |
|
| 3 |
<name>org.txm.libs.office</name> |
|
| 4 |
<comment></comment> |
|
| 5 |
<projects> |
|
| 6 |
</projects> |
|
| 7 |
<buildSpec> |
|
| 8 |
<buildCommand> |
|
| 9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
| 10 |
<arguments> |
|
| 11 |
</arguments> |
|
| 12 |
</buildCommand> |
|
| 13 |
<buildCommand> |
|
| 14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
| 15 |
<arguments> |
|
| 16 |
</arguments> |
|
| 17 |
</buildCommand> |
|
| 18 |
<buildCommand> |
|
| 19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
| 20 |
<arguments> |
|
| 21 |
</arguments> |
|
| 22 |
</buildCommand> |
|
| 23 |
</buildSpec> |
|
| 24 |
<natures> |
|
| 25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
| 26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
| 27 |
</natures> |
|
| 28 |
</projectDescription> |
|
| 0 | 29 | |
| tmp/org.txm.libs.office/src/org/txm/libs/office/ReadODS.java (revision 964) | ||
|---|---|---|
| 1 |
package org.txm.libs.office; |
|
| 2 |
|
|
| 3 |
import java.io.File; |
|
| 4 |
import java.util.ArrayList; |
|
| 5 |
|
|
| 6 |
import org.odftoolkit.simple.SpreadsheetDocument; |
|
| 7 |
import org.odftoolkit.simple.table.Row; |
|
| 8 |
import org.odftoolkit.simple.table.Table; |
|
| 9 |
|
|
| 10 |
public class ReadODS {
|
|
| 11 |
|
|
| 12 |
public static ArrayList<ArrayList<String>> toTable(File inputFile, String sheetname) throws Exception {
|
|
| 13 |
|
|
| 14 |
SpreadsheetDocument spreadsheet = SpreadsheetDocument.loadDocument(inputFile); |
|
| 15 |
|
|
| 16 |
// the first access to the document causes a very long process |
|
| 17 |
int sheetCount = spreadsheet.getSheetCount(); |
|
| 18 |
if (sheetCount < 1) {
|
|
| 19 |
System.out.println("** ReadODS: no sheet found in file. Aborting.");
|
|
| 20 |
return null; |
|
| 21 |
} |
|
| 22 |
|
|
| 23 |
Table table = null; |
|
| 24 |
if (sheetname != null) {
|
|
| 25 |
table = spreadsheet.getSheetByName(sheetname); |
|
| 26 |
} |
|
| 27 |
if (table == null) {
|
|
| 28 |
table = spreadsheet.getSheetByIndex(0); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>(); |
|
| 32 |
|
|
| 33 |
int rowCount = table.getRowCount(); |
|
| 34 |
|
|
| 35 |
for (int it = 0 ; it < rowCount ; it++) {
|
|
| 36 |
ArrayList<String> dataline = new ArrayList<>(); |
|
| 37 |
data.add(dataline); |
|
| 38 |
Row row = table.getRowByIndex(it); |
|
| 39 |
int colCount = row.getCellCount(); |
|
| 40 |
for (int j = 0 ; j < colCount ; j++) {
|
|
| 41 |
String cell = row.getCellByIndex(j).getDisplayText(); |
|
| 42 |
if (cell == null) {
|
|
| 43 |
dataline.add("");
|
|
| 44 |
} else {
|
|
| 45 |
dataline.add(cell); |
|
| 46 |
} |
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
return data; |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
public static void main(String[] args) throws Exception {
|
|
| 54 |
System.out.println(toTable(new File("/home/mdecorde/xml/metadata.ods"), "metadata"));
|
|
| 55 |
} |
|
| 56 |
} |
|
| 0 | 57 | |
| tmp/org.txm.libs.office/build.properties (revision 964) | ||
|---|---|---|
| 1 |
source.. = src/ |
|
| 2 |
output.. = bin/ |
|
| 3 |
bin.includes = META-INF/,\ |
|
| 4 |
.,\ |
|
| 5 |
lib/collection-0.7.jar,\ |
|
| 6 |
lib/commons-cli-1.4.jar,\ |
|
| 7 |
lib/commons-codec-1.11.jar,\ |
|
| 8 |
lib/commons-compress-1.17.jar,\ |
|
| 9 |
lib/commons-csv-1.5.jar,\ |
|
| 10 |
lib/commons-io-2.6.jar,\ |
|
| 11 |
lib/commons-lang3-3.4.jar,\ |
|
| 12 |
lib/httpclient-4.5.5.jar,\ |
|
| 13 |
lib/httpclient-cache-4.5.5.jar,\ |
|
| 14 |
lib/httpcore-4.4.9.jar,\ |
|
| 15 |
lib/jackson-annotations-2.9.0.jar,\ |
|
| 16 |
lib/jackson-core-2.9.5.jar,\ |
|
| 17 |
lib/jackson-databind-2.9.5.jar,\ |
|
| 18 |
lib/java-rdfa-0.4.2.jar,\ |
|
| 19 |
lib/jcl-over-slf4j-1.7.25.jar,\ |
|
| 20 |
lib/jena-arq-3.8.0.jar,\ |
|
| 21 |
lib/jena-base-3.8.0.jar,\ |
|
| 22 |
lib/jena-cmds-3.8.0.jar,\ |
|
| 23 |
lib/jena-core-3.8.0.jar,\ |
|
| 24 |
lib/jena-dboe-base-3.8.0.jar,\ |
|
| 25 |
lib/jena-dboe-index-3.8.0.jar,\ |
|
| 26 |
lib/jena-dboe-trans-data-3.8.0.jar,\ |
|
| 27 |
lib/jena-dboe-transaction-3.8.0.jar,\ |
|
| 28 |
lib/jena-iri-3.8.0.jar,\ |
|
| 29 |
lib/jena-rdfconnection-3.8.0.jar,\ |
|
| 30 |
lib/jena-shaded-guava-3.8.0.jar,\ |
|
| 31 |
lib/jena-tdb-3.8.0.jar,\ |
|
| 32 |
lib/jena-tdb2-3.8.0.jar,\ |
|
| 33 |
lib/jsonld-java-0.12.0.jar,\ |
|
| 34 |
lib/libthrift-0.10.0.jar,\ |
|
| 35 |
lib/log4j-1.2.17.jar,\ |
|
| 36 |
lib/odfdom-java-0.8.11-incubating.jar,\ |
|
| 37 |
lib/simple-odf-0.8.2-incubating.jar,\ |
|
| 38 |
lib/slf4j-api-1.7.25.jar,\ |
|
| 39 |
lib/slf4j-log4j12-1.7.25.jar,\ |
|
| 40 |
lib/xslt-runner-1.2.4-incubating.jar,\ |
|
| 41 |
lib/xslt-runner-task-1.2.4-incubating.jar,\ |
|
| 42 |
lib/commons-beanutils-1.9.2.jar,\ |
|
| 43 |
lib/commons-collections-3.2.2.jar,\ |
|
| 44 |
lib/commons-digester-1.8.1.jar,\ |
|
| 45 |
lib/commons-logging-1.2.jar,\ |
|
| 46 |
lib/commons-validator-1.5.0.jar,\ |
|
| 47 |
lib/jena-core-2.11.2.jar,\ |
|
| 48 |
lib/jena-iri-1.0.2.jar,\ |
|
| 49 |
lib/junit-3.8.1.jar,\ |
|
| 50 |
lib/odfdom-java-0.8.7.jar,\ |
|
| 51 |
lib/org.odftoolkit.odfdom.converter.core-1.0.6.jar,\ |
|
| 52 |
lib/slf4j-log4j12-1.7.6.jar,\ |
|
| 53 |
lib/taglets-0.8.11-incubating.jar,\ |
|
| 54 |
lib/xercesImpl-2.9.1.jar,\ |
|
| 55 |
lib/xml-apis-1.3.04.jar |
|
| 0 | 56 | |
| tmp/org.txm.libs.office/.settings/org.eclipse.jdt.core.prefs (revision 964) | ||
|---|---|---|
| 1 |
eclipse.preferences.version=1 |
|
| 2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
| 3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
|
| 4 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
|
| 5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
| 6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
| 7 |
org.eclipse.jdt.core.compiler.source=1.7 |
|
| 0 | 8 | |
| tmp/org.txm.libs.office/.classpath (revision 964) | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
| 2 |
<classpath> |
|
| 3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> |
|
| 4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
| 5 |
<classpathentry kind="src" path="src"/> |
|
| 6 |
<classpathentry exported="true" kind="lib" path="lib/commons-beanutils-1.9.2.jar"/> |
|
| 7 |
<classpathentry exported="true" kind="lib" path="lib/commons-collections-3.2.2.jar"/> |
|
| 8 |
<classpathentry exported="true" kind="lib" path="lib/commons-digester-1.8.1.jar"/> |
|
| 9 |
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/> |
|
| 10 |
<classpathentry exported="true" kind="lib" path="lib/commons-validator-1.5.0.jar"/> |
|
| 11 |
<classpathentry exported="true" kind="lib" path="lib/java-rdfa-0.4.2.jar"/> |
|
| 12 |
<classpathentry exported="true" kind="lib" path="lib/jena-core-2.11.2.jar"/> |
|
| 13 |
<classpathentry exported="true" kind="lib" path="lib/jena-iri-1.0.2.jar"/> |
|
| 14 |
<classpathentry exported="true" kind="lib" path="lib/junit-3.8.1.jar"/> |
|
| 15 |
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/> |
|
| 16 |
<classpathentry exported="true" kind="lib" path="lib/odfdom-java-0.8.11-incubating.jar"/> |
|
| 17 |
<classpathentry exported="true" kind="lib" path="lib/odfdom-java-0.8.7.jar"/> |
|
| 18 |
<classpathentry exported="true" kind="lib" path="lib/org.odftoolkit.odfdom.converter.core-1.0.6.jar"/> |
|
| 19 |
<classpathentry exported="true" kind="lib" path="lib/simple-odf-0.8.2-incubating.jar"/> |
|
| 20 |
<classpathentry exported="true" kind="lib" path="lib/slf4j-api-1.7.25.jar"/> |
|
| 21 |
<classpathentry exported="true" kind="lib" path="lib/slf4j-log4j12-1.7.6.jar"/> |
|
| 22 |
<classpathentry exported="true" kind="lib" path="lib/taglets-0.8.11-incubating.jar"/> |
|
| 23 |
<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.9.1.jar"/> |
|
| 24 |
<classpathentry exported="true" kind="lib" path="lib/xml-apis-1.3.04.jar"/> |
|
| 25 |
<classpathentry kind="output" path="bin"/> |
|
| 26 |
</classpath> |
|
| 0 | 27 | |
| tmp/org.txm.libs.office/META-INF/MANIFEST.MF (revision 964) | ||
|---|---|---|
| 1 |
Manifest-Version: 1.0 |
|
| 2 |
Bundle-ManifestVersion: 2 |
|
| 3 |
Bundle-Name: org.txm.libs.office |
|
| 4 |
Bundle-SymbolicName: org.txm.libs.office |
|
| 5 |
Bundle-Version: 0.8.2 |
|
| 6 |
Automatic-Module-Name: org.txm.libs.office |
|
| 7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 |
|
| 8 |
Bundle-ClassPath: lib/commons-beanutils-1.9.2.jar, |
|
| 9 |
lib/commons-collections-3.2.2.jar, |
|
| 10 |
lib/commons-digester-1.8.1.jar, |
|
| 11 |
lib/commons-logging-1.2.jar, |
|
| 12 |
lib/commons-validator-1.5.0.jar, |
|
| 13 |
lib/java-rdfa-0.4.2.jar, |
|
| 14 |
lib/jena-core-2.11.2.jar, |
|
| 15 |
lib/jena-iri-1.0.2.jar, |
|
| 16 |
lib/junit-3.8.1.jar, |
|
| 17 |
lib/log4j-1.2.17.jar, |
|
| 18 |
lib/odfdom-java-0.8.11-incubating.jar, |
|
| 19 |
lib/odfdom-java-0.8.7.jar, |
|
| 20 |
lib/org.odftoolkit.odfdom.converter.core-1.0.6.jar, |
|
| 21 |
lib/simple-odf-0.8.2-incubating.jar, |
|
| 22 |
lib/slf4j-api-1.7.25.jar, |
|
| 23 |
lib/slf4j-log4j12-1.7.6.jar, |
|
| 24 |
lib/taglets-0.8.11-incubating.jar, |
|
| 25 |
lib/xercesImpl-2.9.1.jar, |
|
| 26 |
lib/xml-apis-1.3.04.jar, |
|
| 27 |
. |
|
| 28 |
Export-Package: |
|
| 29 |
org.txm.libs.office |
|
| 30 |
Bundle-Vendor: Apache ODF Toolkit (incubating) |
|
| 31 |
Require-Bundle: org.apache.xerces;bundle-version="2.9.0" |
|
| 0 | 32 | |
Formats disponibles : Unified diff