|
|
@ -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,34 +38,58 @@ 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) { |
|
|
|
currentElementData = null; |
|
|
|
return; |
|
|
|
isTagt = true; |
|
|
|
} |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
switch (name) { |
|
|
|
currentData = null; |
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: |
|
|
|
} else if (RPH_TAG.equals(name)) { |
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: |
|
|
|
ignoreTagt = true; |
|
|
|
currentElementData = null; |
|
|
|
|
|
|
|
isTagt = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: |
|
|
|
|
|
|
|
currentData = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: |
|
|
|
|
|
|
|
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) { |
|
|
|
if (currentElementData != null) { |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch (name) { |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG: |
|
|
|
|
|
|
|
if (currentElementData != null) { |
|
|
|
|
|
|
|
if (currentData == null) { |
|
|
|
|
|
|
|
currentData = new StringBuilder(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
currentData.append(currentElementData); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
isTagt = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG: |
|
|
|
|
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG: |
|
|
|
if (currentData == null) { |
|
|
|
if (currentData == null) { |
|
|
|
currentData = new StringBuilder(); |
|
|
|
readCache.put(null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
readCache.put(currentData.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
currentData.append(currentElementData); |
|
|
|
break; |
|
|
|
} |
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG: |
|
|
|
isTagt = false; |
|
|
|
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG: |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
ignoreTagt = false; |
|
|
|
if (currentData == null) { |
|
|
|
break; |
|
|
|
readCache.put(null); |
|
|
|
default: |
|
|
|
} else { |
|
|
|
// ignore
|
|
|
|
readCache.put(currentData.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (RPH_TAG.equals(name)) { |
|
|
|
|
|
|
|
ignoreTagt = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|