working on xslx

This commit is contained in:
Jörg Prante 2024-05-16 16:33:21 +02:00
parent d0f7392cf0
commit 0667b90ac4
476 changed files with 2227 additions and 2317 deletions

View file

@ -1,18 +1,13 @@
plugins {
id "checkstyle"
id "pmd"
id 'maven-publish'
id 'signing'
id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-1"
id "com.github.spotbugs" version "6.0.0-beta.3"
id "org.cyclonedx.bom" version "1.7.4"
id "org.xbib.gradle.plugin.asciidoctor" version "3.0.0"
}
wrapper {
gradleVersion = libs.versions.gradle.get()
distributionType = Wrapper.DistributionType.ALL
distributionType = Wrapper.DistributionType.BIN
}
ext {
@ -31,16 +26,10 @@ ext {
}
subprojects {
//apply from: rootProject.file('gradle/ide/idea.gradle')
apply from: rootProject.file('gradle/repositories/maven.gradle')
apply from: rootProject.file('gradle/compile/java.gradle')
apply from: rootProject.file('gradle/test/junit5.gradle')
apply from: rootProject.file('gradle/documentation/asciidoc.gradle')
apply from: rootProject.file('gradle/quality/checkstyle.gradle')
apply from: rootProject.file('gradle/quality/pmd.gradle')
//apply from: rootProject.file('gradle/quality/spotbugs.gradle')
apply from: rootProject.file('gradle/publish/maven.gradle')
}
apply from: rootProject.file('gradle/publish/sonatype.gradle')
apply from: rootProject.file('gradle/publish/forgejo.gradle')
apply from: rootProject.file('gradle/quality/cyclonedx.gradle')

View file

@ -1,28 +0,0 @@
/*********************************************************************
*
* Copyright (C) 2002 Andrew Khan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
/**
* Interface for cell formats - used for typing information
*
* @deprecated Repackaged as jxl.format.CellFormat
*/
public interface CellFormat extends jxl.format.CellFormat {
}

View file

@ -0,0 +1,4 @@
module org.xbib.datastructures.xslx {
requires java.xml;
exports org.xbib.datastructures.xslx;
}

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
public class Cell {
Cell(String r, String s, String t, String v, String text) {

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.support;
package org.xbib.datastructures.xslx;
public class CellFormat {
public CellFormat() {

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;

View file

@ -1,18 +1,21 @@
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
public interface ExcelRowIterator {
public void init();
void init() throws IOException, XMLStreamException;
public boolean nextRow();
boolean nextRow();
public String getCellValue(int col);
String getCellValue(int col);
public int getCellCount();
int getCellCount();
public byte getSheetIndex();
byte getSheetIndex();
public int getRowPos();
int getRowPos();
public void prevRow();
void prevRow();
}

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
public class FontRegion {

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
public abstract class IndexedObject {
int index;

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamReader;

View file

@ -1,9 +1,8 @@
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import com.incesoft.tools.excel.support.XLSReaderSupport;
import com.incesoft.tools.excel.support.XLSXReaderSupport;
import java.io.IOException;
abstract public class ReaderSupport {
@ -14,7 +13,7 @@ abstract public class ReaderSupport {
abstract public void open();
abstract public ExcelRowIterator rowIterator();
abstract public ExcelRowIterator rowIterator() throws XMLStreamException, IOException;
abstract public void close();

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

View file

@ -1,6 +1,7 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -9,8 +10,8 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import com.incesoft.tools.excel.xlsx.SimpleXLSXWorkbook.ModifyEntry;
import com.incesoft.tools.excel.xlsx.SimpleXLSXWorkbook.XMLStreamCreator;
import org.xbib.datastructures.xslx.SimpleXLSXWorkbook.ModifyEntry;
import org.xbib.datastructures.xslx.SimpleXLSXWorkbook.XMLStreamCreator;
/**
* One Sheet in a workbook.It provides read and write functions of the
@ -42,7 +43,7 @@ public class Sheet {
*/
boolean alreadyParsed = false;
void parseAllRows() {
void parseAllRows() throws IOException {
if (!alreadyParsed) {
alreadyParsed = true;
new SheetRowReader(this, workbook.getSheetReader(sheetIndex + 1),
@ -216,7 +217,7 @@ public class Sheet {
}
public SheetRowReader newReader() {
public SheetRowReader newReader() throws IOException {
return new SheetRowReader(this,
workbook.getSheetReader(sheetIndex + 1), false);
}
@ -240,7 +241,7 @@ public class Sheet {
private int rowCount = -2;
// count of the lazy or non-lazy rows
public int getRowCount() {
public int getRowCount() throws IOException, XMLStreamException {
if (alreadyParsed && addToMemory) {
return parsedRows.size();
}
@ -250,41 +251,35 @@ public class Sheet {
try {
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <worksheet ...><dimension ref="A1:C3"/>...<sheetData>
loopR: while (reader.hasNext()) {
loopR:
while (reader.hasNext()) {
int type = reader.next();
switch (type) {
case XMLStreamReader.START_ELEMENT:
if ("dimension".equals(reader.getLocalName())) {
String v = reader.getAttributeValue(null, "ref");
if (v != null) {
String[] spanPair = v.replaceAll("[A-Z]", "")
.split(":");
if (spanPair.length == 2) {
try {
rowCount = Integer.valueOf(spanPair[1])
- Integer.valueOf(spanPair[0])
+ 1;
} catch (NumberFormatException e) {
}
break loopR;
}
}
} else if ("row".equals(reader.getLocalName())) {
int r = Integer.valueOf(reader.getAttributeValue(
null, "r"));
if (r > rowCount)
rowCount = r;
}
break;
}
if (type == XMLStreamReader.START_ELEMENT) {
if ("dimension".equals(reader.getLocalName())) {
String v = reader.getAttributeValue(null, "ref");
if (v != null) {
String[] spanPair = v.replaceAll("[A-Z]", "")
.split(":");
if (spanPair.length == 2) {
try {
rowCount = Integer.valueOf(spanPair[1])
- Integer.valueOf(spanPair[0])
+ 1;
} catch (NumberFormatException e) {
}
break loopR;
}
}
} else if ("row".equals(reader.getLocalName())) {
int r = Integer.valueOf(reader.getAttributeValue(
null, "r"));
if (r > rowCount)
rowCount = r;
}
}
}
} catch (XMLStreamException e) {
throw new RuntimeException(e);
} finally {
try {
reader.close();
} catch (XMLStreamException e) {
}
reader.close();
}
}
return rowCount;
@ -637,16 +632,7 @@ public class Sheet {
private boolean merged = false;
/**
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <worksheet
* xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
* xmlns:r=
* "http://schemas.openxmlformats.org/officeDocument/2006/relationships" ><sheetData>
*
* @param writer
* @throws XMLStreamException
*/
void mergeSheet() throws XMLStreamException {
void mergeSheet() throws XMLStreamException, IOException {
if (merged) {
writeSheet();
return;

View file

@ -1,11 +1,11 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import java.util.StringTokenizer;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import com.incesoft.tools.excel.xlsx.SimpleXLSXWorkbook.XMLStreamCreator;
import org.xbib.datastructures.xslx.SimpleXLSXWorkbook.XMLStreamCreator;
public class SheetCommentWriter {

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.xlsx;
package org.xbib.datastructures.xslx;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -32,31 +32,12 @@ import javax.xml.stream.XMLStreamWriter;
/**
* A simple implementation of OOXML(Excel part) to read and modify Excel 2007+
* documents
*
*/
public class SimpleXLSXWorkbook {
static {
// this the fastest stax implementation by test,especially when doing
// output
if ("false".equals(System.getProperty("ince.tools.excel.disableXMLOptimize"))) {
System.setProperty("javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory");
System.setProperty("javax.xml.stream.XMLOutputFactory", "com.ctc.wstx.stax.WstxOutputFactory");
}
}
ZipFile zipfile;
private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
private InputStream findData(String name) {
try {
ZipEntry entry = zipfile.getEntry(name);
if (entry != null) {
return zipfile.getInputStream(entry);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
private ZipFile zipfile;
private static final String PATH_XL_RELATION = "xl/_rels/workbook.xml.rels";
@ -66,9 +47,9 @@ public class SimpleXLSXWorkbook {
private static final String PATH_CONTENT_TYPES = "[Content_Types].xml";
static private List<Pattern> blackListPatterns = new ArrayList<Pattern>();
private static final List<Pattern> blackListPatterns = new ArrayList<Pattern>();
static private List<String> blackList = Arrays.asList(".*comments\\d+\\.xml", ".*calcChain\\.xml",
private static final List<String> blackList = Arrays.asList(".*comments\\d+\\.xml", ".*calcChain\\.xml",
".*drawings/vmlDrawing\\d+\\.vml");
static {
for (String pstr : blackList) {
@ -76,16 +57,22 @@ public class SimpleXLSXWorkbook {
}
}
public SimpleXLSXWorkbook(File file) {
try {
this.zipfile = new ZipFile(file);
InputStream stream = findData(PATH_SHAREDSTRINGS);
if (stream != null) {
parseSharedStrings(stream);
public SimpleXLSXWorkbook() {
sheets.add(new Sheet(0, this));
}
public SimpleXLSXWorkbook(File file) throws IOException, XMLStreamException {
this.zipfile = new ZipFile(file);
InputStream stream = findData(PATH_SHAREDSTRINGS);
if (stream != null) {
parseSharedStrings(stream);
}
for (int i = 0; true; i++) {
ZipEntry entry = zipfile.getEntry(getSheetPath(i + 1));
if (entry == null) {
break;
}
initSheets();
} catch (Exception e) {
throw new RuntimeException(e);
sheets.add(new Sheet(i, this));
}
}
@ -170,17 +157,6 @@ public class SimpleXLSXWorkbook {
return null;
}
// int getSharedStringIndex(String string) {
// Integer i = (Integer) sharedStrings.inverseBidiMap().get(string);
// if (i != null) {
// return i;
// } else {
// return -1;
// }
// }
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
private String getSheetPath(int i) {
return String.format(PATH_SHEET, i);
}
@ -193,7 +169,8 @@ public class SimpleXLSXWorkbook {
return String.format(PATH_SHEET_COMMENT_VMLDRAWING, i);
}
private void parseSharedStrings(InputStream inputStream) throws Exception {
private void parseSharedStrings(InputStream inputStream)
throws XMLStreamException {
XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream);
int type;
boolean si = false;
@ -241,10 +218,23 @@ public class SimpleXLSXWorkbook {
private static final String PATH_STYLES = "xl/styles.xml";
private static final String STR_XML_HEAD = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
private static final byte[] DATA_XL_WORKSHEETS__RELS_SHEET = (STR_XML_HEAD + "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"></Relationships>")
.getBytes();
XMLStreamReader getReader(String resourceId) {
XMLStreamReader getSheetReader(Integer sheetId) throws IOException {
if (sheetId == null) {
sheetId = 1;
}
return getReader(getSheetPath(sheetId));
}
XMLStreamReader getStylesReader() throws IOException {
return getReader(PATH_STYLES);
}
private XMLStreamReader getReader(String resourceId) throws IOException {
InputStream stream = findData(resourceId);
if (stream == null) {
if (resourceId.startsWith("xl/worksheets/_rels/sheet")) {
@ -262,30 +252,9 @@ public class SimpleXLSXWorkbook {
}
}
XMLStreamReader getSheetReader(Integer sheetId) {
if (sheetId == null) {
sheetId = 1;
}
return getReader(getSheetPath(sheetId));
}
XMLStreamReader getStylesReader() {
return getReader(PATH_STYLES);
}
// SHEET>>>
List<Sheet> sheets = new ArrayList<Sheet>();
private void initSheets() {
for (int i = 0; true; i++) {
ZipEntry entry = zipfile.getEntry(getSheetPath(i + 1));
if (entry == null) {
break;
}
sheets.add(new Sheet(i, this));
}
}
/**
* create new sheet added to exists sheet list
*/
@ -299,11 +268,11 @@ public class SimpleXLSXWorkbook {
return sheets.size();
}
public Sheet getSheet(int i) {
public Sheet getSheet(int i) throws IOException {
return getSheet(i, true);
}
public Sheet getSheet(int i, boolean parseAllRow) {
public Sheet getSheet(int i, boolean parseAllRow) throws IOException {
if (i >= sheets.size())
throw new IllegalArgumentException("sheet " + i + " not exists!SheetCount=" + sheets.size());
Sheet sheet = sheets.get(i);
@ -419,7 +388,7 @@ public class SimpleXLSXWorkbook {
writer.writeEndElement();// end sst
}
private void mergeStyles(XMLStreamWriter writer) throws XMLStreamException {
private void mergeStyles(XMLStreamWriter writer) throws XMLStreamException, IOException {
prepareStylesCount();
XMLStreamReader reader = getStylesReader();
@ -606,36 +575,32 @@ public class SimpleXLSXWorkbook {
boolean stylesCountLoaded = false;
private void prepareStylesCount() {
private void prepareStylesCount() throws XMLStreamException, IOException {
if (stylesCountLoaded)
return;
stylesCountLoaded = true;
try {
XMLStreamReader reader = getStylesReader();
loop1: while (reader.hasNext()) {
int event = reader.next();
switch (event) {
case XMLStreamReader.START_ELEMENT:
if ("fonts".equals(reader.getLocalName())) {
fontsCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
}
if ("fills".equals(reader.getLocalName())) {
fillsCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
}
if ("cellXfs".equals(reader.getLocalName())) {
stylesCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
break loop1;
}
break;
case XMLStreamReader.END_ELEMENT:
break;
default:
break;
XMLStreamReader reader = getStylesReader();
loop1: while (reader.hasNext()) {
int event = reader.next();
switch (event) {
case XMLStreamReader.START_ELEMENT:
if ("fonts".equals(reader.getLocalName())) {
fontsCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
}
if ("fills".equals(reader.getLocalName())) {
fillsCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
}
if ("cellXfs".equals(reader.getLocalName())) {
stylesCountOffset = Integer.valueOf(reader.getAttributeValue(null, "count"));
break loop1;
}
break;
case XMLStreamReader.END_ELEMENT:
break;
default:
break;
}
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
}
@ -652,7 +617,7 @@ public class SimpleXLSXWorkbook {
return new Fill();
}
public CellStyle createStyle(Font font, Fill fill) {
public CellStyle createStyle(Font font, Fill fill) throws XMLStreamException, IOException {
if (font == null && fill == null) {
throw new IllegalArgumentException("either font or fill is required");
}
@ -831,14 +796,10 @@ public class SimpleXLSXWorkbook {
/**
* merge the sheet's modifications
*/
public void commitSheetModifications() {
try {
if (lastCommitSheet == null)
throw new IllegalStateException("plz call beginCommitSheet(Sheet) first");
lastCommitSheet.mergeSheet();
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
public void commitSheetModifications() throws XMLStreamException, IOException {
if (lastCommitSheet == null)
throw new IllegalStateException("plz call beginCommitSheet(Sheet) first");
lastCommitSheet.mergeSheet();
}
/**
@ -1065,21 +1026,6 @@ public class SimpleXLSXWorkbook {
commiter.endCommit();
}
// MODIFY <<<
// TEST
public static void testMergeStyles(SimpleXLSXWorkbook excel, XMLStreamWriter writer) throws Exception {
// CellStyle style = excel.createStyle();
// style.setFont(new Font());
// style.getFont().setColor("FFFF0000");
// style = excel.createStyle();
// style.setFont(new Font());
// style.setFill(new Fill());
// style.getFont().setColor("FF0000FF");
// style.getFill().setFgColor("FF00FF00");
}
@SuppressWarnings("unchecked")
static private class BidirectionMap implements Map {
private Map values = new LinkedHashMap();
@ -1141,4 +1087,12 @@ public class SimpleXLSXWorkbook {
}
}
private InputStream findData(String name) throws IOException {
ZipEntry entry = zipfile.getEntry(name);
if (entry != null) {
return zipfile.getInputStream(entry);
}
return null;
}
}

View file

@ -1,12 +1,10 @@
package org.xbib.datastructures.xslx;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import com.incesoft.tools.excel.support.CellFormat;
import com.incesoft.tools.excel.support.XLSWriterSupport;
import com.incesoft.tools.excel.support.XLSXWriterSupport;
abstract public class WriterSupport {
public final static int TYPE_XLS = 1;
@ -28,11 +26,11 @@ abstract public class WriterSupport {
abstract public void open();
abstract public void createNewSheet();
abstract public void createNewSheet() throws IOException;
abstract public void writeRow(String[] rowData);
abstract public void writeRow(String[] rowData) throws XMLStreamException, IOException;
abstract public void writeRow(String[] rowData, CellFormat[] formats);
abstract public void writeRow(String[] rowData, CellFormat[] formats) throws XMLStreamException, IOException;
abstract public void close();
@ -69,10 +67,10 @@ abstract public class WriterSupport {
protected int sheetIndex = -1;
public void increaseRow() {
public void increaseRow() throws IOException {
rowpos++;
if (rowpos > getMaxRowNumOfSheet()) {// 判断是否需要新建一个sheet
if (rowpos > getMaxRowNumOfSheet()) {
sheetIndex++;
createNewSheet();
rowpos = -1;

View file

@ -1,16 +1,13 @@
package com.incesoft.tools.excel.support;
package org.xbib.datastructures.xslx;
import java.io.File;
import java.text.SimpleDateFormat;
import org.xbib.datastructures.xslx.ExcelRowIterator;
import org.xbib.datastructures.xslx.ReaderSupport;
import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;
import org.xbib.datastructures.xslx.jxl.Cell;
import org.xbib.datastructures.xslx.jxl.CellType;
import org.xbib.datastructures.xslx.jxl.DateCell;
import org.xbib.datastructures.xslx.jxl.Sheet;
import org.xbib.datastructures.xslx.jxl.Workbook;
public class XLSReaderSupport extends ReaderSupport {

View file

@ -1,4 +1,4 @@
package com.incesoft.tools.excel.support;
package org.xbib.datastructures.xslx;
import java.io.IOException;
import java.util.ArrayList;
@ -7,18 +7,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.RGB;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import org.xbib.datastructures.xslx.WriterSupport;
import org.xbib.datastructures.xslx.jxl.Workbook;
import org.xbib.datastructures.xslx.jxl.format.Colour;
import org.xbib.datastructures.xslx.jxl.format.RGB;
import org.xbib.datastructures.xslx.jxl.write.Label;
import org.xbib.datastructures.xslx.jxl.write.WritableCell;
import org.xbib.datastructures.xslx.jxl.write.WritableCellFormat;
import org.xbib.datastructures.xslx.jxl.write.WritableFont;
import org.xbib.datastructures.xslx.jxl.write.WritableSheet;
import org.xbib.datastructures.xslx.jxl.write.WritableWorkbook;
import org.xbib.datastructures.xslx.jxl.write.WriteException;
public class XLSWriterSupport extends WriterSupport {
WritableSheet sheet;

View file

@ -1,13 +1,11 @@
package com.incesoft.tools.excel.support;
package org.xbib.datastructures.xslx;
import java.io.File;
import java.io.IOException;
import org.xbib.datastructures.xslx.ExcelRowIterator;
import org.xbib.datastructures.xslx.ReaderSupport;
import com.incesoft.tools.excel.xlsx.Cell;
import com.incesoft.tools.excel.xlsx.Sheet;
import com.incesoft.tools.excel.xlsx.SimpleXLSXWorkbook;
import com.incesoft.tools.excel.xlsx.Sheet.SheetRowReader;
import org.xbib.datastructures.xslx.Sheet.SheetRowReader;
import javax.xml.stream.XMLStreamException;
public class XLSXReaderSupport extends ReaderSupport {
@ -33,7 +31,7 @@ public class XLSXReaderSupport extends ReaderSupport {
|| curRow[col] == null)
return null;
String v = curRow[col].getValue();
return v == null || v.trim().length() == 0 ? null : v.trim();
return v == null || v.trim().isEmpty() ? null : v.trim();
}
public int getRowPos() {
@ -46,7 +44,7 @@ public class XLSXReaderSupport extends ReaderSupport {
SheetRowReader reader;
public void init() {
public void init() throws IOException {
reader = sheet.newReader();
}
@ -85,14 +83,14 @@ public class XLSXReaderSupport extends ReaderSupport {
int rowPos = -1;
public void init() {
public void init() throws XMLStreamException, IOException {
currentSheetRowCount = sheet.getRowCount();
}
public boolean nextRow() {
rowPos++;
if (rowPos == currentSheetRowCount) {// 当读取最后一行,如果当前读取的是当前sheet的最后一行
return false;// 所有记录里面的最后一行
if (rowPos == currentSheetRowCount) {
return false;
}
return true;
}
@ -101,7 +99,7 @@ public class XLSXReaderSupport extends ReaderSupport {
if (col < 0)
return null;
String v = sheet.getCellValue(rowPos, col);
return v == null || v.trim().length() == 0 ? null : v.trim();
return v == null || v.trim().isEmpty() ? null : v.trim();
}
public byte getSheetIndex() {
@ -138,7 +136,7 @@ public class XLSXReaderSupport extends ReaderSupport {
}
}
public ExcelRowIterator rowIterator() {
public ExcelRowIterator rowIterator() throws XMLStreamException, IOException {
ExcelRowIterator iterator = lazy ? new LazyXLSXObjectIterator()
: new XLSXObjectIterator();
iterator.init();

View file

@ -1,25 +1,15 @@
package com.incesoft.tools.excel.support;
package org.xbib.datastructures.xslx;
import java.io.File;
import javax.xml.stream.XMLStreamException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.xbib.datastructures.xslx.WriterSupport;
import com.incesoft.tools.excel.xlsx.CellStyle;
import com.incesoft.tools.excel.xlsx.Fill;
import com.incesoft.tools.excel.xlsx.Font;
import com.incesoft.tools.excel.xlsx.Sheet;
import com.incesoft.tools.excel.xlsx.SimpleXLSXWorkbook;
public class XLSXWriterSupport extends WriterSupport {
SimpleXLSXWorkbook workbook;
public void open() {
if (getClass().getResource("/empty.xlsx") == null) {
throw new IllegalStateException("no empty.xlsx found in classpath");
}
workbook = new SimpleXLSXWorkbook(new File(getClass().getResource("/empty.xlsx").getFile()));
workbook = new SimpleXLSXWorkbook();
}
Sheet sheet;
@ -28,17 +18,17 @@ public class XLSXWriterSupport extends WriterSupport {
return Integer.MAX_VALUE / 2;
}
public void writeRow(String[] rowData) {
public void writeRow(String[] rowData) throws XMLStreamException, IOException {
writeRow(rowData, null);
}
public void writeRow(String[] rowData, CellFormat[] formats) {
public void writeRow(String[] rowData, CellFormat[] formats) throws XMLStreamException, IOException {
for (int col = 0; col < rowData.length; col++) {
String string = rowData[col];
if (string == null)
continue;
CellFormat format = null;
if (formats != null && formats.length > 0) {
if (formats != null) {
for (CellFormat cellFormat : formats) {
if (cellFormat != null && cellFormat.getCellIndex() == col) {
format = cellFormat;
@ -92,7 +82,7 @@ public class XLSXWriterSupport extends WriterSupport {
}
}
public void createNewSheet() {
public void createNewSheet() throws IOException {
if (sheetIndex > 0) {
throw new IllegalStateException("only one sheet allowed");
}

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
/**
* This type represents the Microsoft concept of a Boolean. Accordingly, this

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
/**
* A mixin interface for numerical formulas, which combines the interfaces

View file

@ -17,9 +17,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
import jxl.format.CellFormat;
import org.xbib.datastructures.xslx.jxl.format.CellFormat;
/**
* Represents an individual Cell within a Sheet. May be queried for its

View file

@ -17,9 +17,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
import jxl.biff.BaseCellFeatures;
import org.xbib.datastructures.xslx.jxl.biff.BaseCellFeatures;
/**
* Container for any additional cell features

View file

@ -17,9 +17,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
import jxl.write.WritableWorkbook;
import org.xbib.datastructures.xslx.jxl.write.WritableWorkbook;
import org.xbib.datastructures.xslx.jxl.biff.formula.ExternalSheet;
/**
* Exposes some cell reference helper methods to the public interface.
@ -41,7 +42,7 @@ public final class CellReferenceHelper {
* @param buf the string buffer to append
*/
public static void getCellReference(int column, int row, StringBuffer buf) {
jxl.biff.CellReferenceHelper.getCellReference(column, row, buf);
org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference(column, row, buf);
}
/**
@ -58,7 +59,7 @@ public final class CellReferenceHelper {
int row,
boolean rowabs,
StringBuffer buf) {
jxl.biff.CellReferenceHelper.getCellReference(column, colabs,
org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference(column, colabs,
row, rowabs,
buf);
}
@ -72,7 +73,7 @@ public final class CellReferenceHelper {
* @return the cell reference
*/
public static String getCellReference(int column, int row) {
return jxl.biff.CellReferenceHelper.getCellReference(column, row);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference(column, row);
}
/**
@ -82,7 +83,7 @@ public final class CellReferenceHelper {
* @return the column portion of the cell reference
*/
public static int getColumn(String s) {
return jxl.biff.CellReferenceHelper.getColumn(s);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getColumn(s);
}
/**
@ -92,7 +93,7 @@ public final class CellReferenceHelper {
* @return the letter for that column number
*/
public static String getColumnReference(int c) {
return jxl.biff.CellReferenceHelper.getColumnReference(c);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getColumnReference(c);
}
/**
@ -102,7 +103,7 @@ public final class CellReferenceHelper {
* @return the row number
*/
public static int getRow(String s) {
return jxl.biff.CellReferenceHelper.getRow(s);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getRow(s);
}
/**
@ -112,7 +113,7 @@ public final class CellReferenceHelper {
* @return TRUE if the column is relative, FALSE otherwise
*/
public static boolean isColumnRelative(String s) {
return jxl.biff.CellReferenceHelper.isColumnRelative(s);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.isColumnRelative(s);
}
/**
@ -122,7 +123,7 @@ public final class CellReferenceHelper {
* @return TRUE if the row is relative, FALSE otherwise
*/
public static boolean isRowRelative(String s) {
return jxl.biff.CellReferenceHelper.isRowRelative(s);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.isRowRelative(s);
}
/**
@ -138,8 +139,8 @@ public final class CellReferenceHelper {
public static void getCellReference
(int sheet, int column, int row,
Workbook workbook, StringBuffer buf) {
jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook, buf);
org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (ExternalSheet) workbook, buf);
}
/**
@ -157,8 +158,8 @@ public final class CellReferenceHelper {
int row,
WritableWorkbook workbook,
StringBuffer buf) {
jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook, buf);
org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (ExternalSheet) workbook, buf);
}
/**
@ -180,9 +181,9 @@ public final class CellReferenceHelper {
boolean rowabs,
Workbook workbook,
StringBuffer buf) {
jxl.biff.CellReferenceHelper.getCellReference
org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, colabs, row, rowabs,
(jxl.biff.formula.ExternalSheet) workbook, buf);
(ExternalSheet) workbook, buf);
}
/**
@ -199,8 +200,8 @@ public final class CellReferenceHelper {
int column,
int row,
Workbook workbook) {
return jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (ExternalSheet) workbook);
}
/**
@ -217,8 +218,8 @@ public final class CellReferenceHelper {
int column,
int row,
WritableWorkbook workbook) {
return jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (jxl.biff.formula.ExternalSheet) workbook);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getCellReference
(sheet, column, row, (ExternalSheet) workbook);
}
@ -229,7 +230,7 @@ public final class CellReferenceHelper {
* @return the sheet name
*/
public static String getSheet(String ref) {
return jxl.biff.CellReferenceHelper.getSheet(ref);
return org.xbib.datastructures.xslx.jxl.biff.CellReferenceHelper.getSheet(ref);
}
/**

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
package jxl;
package org.xbib.datastructures.xslx.jxl;
/**
* An enumeration type listing the available content types for a cell

View file

@ -17,9 +17,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************