|
|
@ -4,6 +4,7 @@ import org.xml.sax.Attributes; |
|
|
|
import org.xml.sax.helpers.DefaultHandler; |
|
|
|
import org.xml.sax.helpers.DefaultHandler; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.cache.ReadCache; |
|
|
|
import com.alibaba.excel.cache.ReadCache; |
|
|
|
|
|
|
|
import com.alibaba.excel.constant.ExcelXmlConstants; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sax read sharedStringsTable.xml |
|
|
|
* Sax read sharedStringsTable.xml |
|
|
@ -11,12 +12,6 @@ import com.alibaba.excel.cache.ReadCache; |
|
|
|
* @author Jiaju Zhuang |
|
|
|
* @author Jiaju Zhuang |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
private static final String T_TAG = "t"; |
|
|
|
|
|
|
|
private static final String SI_TAG = "si"; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Mac 2016 2017 will have this extra field to ignore |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final String RPH_TAG = "rPh"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The final piece of data |
|
|
|
* The final piece of data |
|
|
@ -43,19 +38,36 @@ public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void startElement(String uri, String localName, String name, Attributes attributes) { |
|
|
|
public void startElement(String uri, String localName, String name, Attributes attributes) { |
|
|
|
if (T_TAG.equals(name)) { |
|
|
|
if (name == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch (name) { |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: |
|
|
|
currentElementData = null; |
|
|
|
currentElementData = null; |
|
|
|
isTagt = true; |
|
|
|
isTagt = true; |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: |
|
|
|
currentData = null; |
|
|
|
currentData = null; |
|
|
|
} else if (RPH_TAG.equals(name)) { |
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: |
|
|
|
ignoreTagt = true; |
|
|
|
ignoreTagt = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
// ignore
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void endElement(String uri, String localName, String name) { |
|
|
|
public void endElement(String uri, String localName, String name) { |
|
|
|
if (T_TAG.equals(name)) { |
|
|
|
if (name == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch (name) { |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: |
|
|
|
if (currentElementData != null) { |
|
|
|
if (currentElementData != null) { |
|
|
|
if (currentData == null) { |
|
|
|
if (currentData == null) { |
|
|
|
currentData = new StringBuilder(); |
|
|
|
currentData = new StringBuilder(); |
|
|
@ -63,14 +75,21 @@ public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
currentData.append(currentElementData); |
|
|
|
currentData.append(currentElementData); |
|
|
|
} |
|
|
|
} |
|
|
|
isTagt = false; |
|
|
|
isTagt = false; |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: |
|
|
|
if (currentData == null) { |
|
|
|
if (currentData == null) { |
|
|
|
readCache.put(null); |
|
|
|
readCache.put(null); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
readCache.put(currentData.toString()); |
|
|
|
readCache.put(currentData.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (RPH_TAG.equals(name)) { |
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: |
|
|
|
ignoreTagt = false; |
|
|
|
ignoreTagt = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
// ignore
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|