Skip to content

Commit 513c6f6

Browse files
support for shared strings composed of multiple text parts
1 parent dbfc7c7 commit 513c6f6

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/com/inet/excel/parser/ExcelParser.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 - 2024 i-net software
2+
* Copyright 2023 - 2025 i-net software
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -269,12 +269,21 @@ private void initSharedStrings( ZipFile zipFile ) {
269269
try {
270270
List<String> list = new ArrayList<>();
271271

272+
String text = "";
272273
while( reader.hasNext() ) {
273274
reader.next();
274-
if( reader.getEventType() == XMLStreamReader.START_ELEMENT ) {
275+
276+
int eventType = reader.getEventType();
277+
if( eventType == XMLStreamReader.START_ELEMENT ) {
275278
String localName = reader.getLocalName();
276279
if( "t".equals( localName ) ) {
277-
list.add( reader.getElementText() );
280+
text += reader.getElementText();
281+
}
282+
} else if( eventType == XMLStreamReader.END_ELEMENT ) {
283+
String localName = reader.getLocalName();
284+
if( "si".equals( localName ) ) {
285+
list.add( text );
286+
text = "";
278287
}
279288
}
280289
}

test/com/inet/excel/parser/ExcelParserTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 - 2024 i-net software
2+
* Copyright 2023 - 2025 i-net software
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -377,4 +377,19 @@ public void getColumnTypes_returns_value_types_for_columns_from_specified_sheet(
377377

378378
assertEquals( asList( ValueType.VARCHAR, ValueType.VARCHAR, ValueType.DATE ), parser.getColumnTypes( "RowLimit" ) );
379379
}
380+
381+
@Test
382+
public void supports_shared_strings_composed_of_multiple_text_parts() {
383+
File resource = new File( ExcelParserTest.class.getResource( "./files/sharedStrings_with_multiple_text_parts.xlsx" ).getPath() );
384+
385+
// rows
386+
ExcelParser parser = new ExcelParser( resource.toPath(), false );
387+
List<List<Object>> expectedRows = asList( asList( "one two three", "four five" ),
388+
asList( "six seven", "eight nine ten" ) );
389+
assertEquals( expectedRows, parser.getRows( "Sheet1", 1, 2 ) );
390+
391+
// columns
392+
parser = new ExcelParser( resource.toPath(), true );
393+
assertEquals( asList( "one two three", "four five" ), parser.getColumnNames( "Sheet1" ) );
394+
}
380395
}

0 commit comments

Comments
 (0)