|
|
@ -13,6 +13,11 @@ import com.alibaba.excel.cache.ReadCache; |
|
|
|
public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
private static final String T_TAG = "t"; |
|
|
|
private static final String T_TAG = "t"; |
|
|
|
private static final String SI_TAG = "si"; |
|
|
|
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 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -23,6 +28,14 @@ public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
private StringBuilder currentElementData; |
|
|
|
private StringBuilder currentElementData; |
|
|
|
|
|
|
|
|
|
|
|
private ReadCache readCache; |
|
|
|
private ReadCache readCache; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Some fields in the T tag need to be ignored |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean ignoreTagt = false; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The only time you need to read the characters in the T tag is when it is used |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean isTagt = false; |
|
|
|
|
|
|
|
|
|
|
|
public SharedStringsTableHandler(ReadCache readCache) { |
|
|
|
public SharedStringsTableHandler(ReadCache readCache) { |
|
|
|
this.readCache = readCache; |
|
|
|
this.readCache = readCache; |
|
|
@ -32,8 +45,11 @@ public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
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 (T_TAG.equals(name)) { |
|
|
|
currentElementData = null; |
|
|
|
currentElementData = null; |
|
|
|
|
|
|
|
isTagt = true; |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
currentData = null; |
|
|
|
currentData = null; |
|
|
|
|
|
|
|
} else if (RPH_TAG.equals(name)) { |
|
|
|
|
|
|
|
ignoreTagt = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -46,17 +62,23 @@ public class SharedStringsTableHandler extends DefaultHandler { |
|
|
|
} |
|
|
|
} |
|
|
|
currentData.append(currentElementData); |
|
|
|
currentData.append(currentElementData); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
isTagt = false; |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
} else if (SI_TAG.equals(name)) { |
|
|
|
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)) { |
|
|
|
|
|
|
|
ignoreTagt = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void characters(char[] ch, int start, int length) { |
|
|
|
public void characters(char[] ch, int start, int length) { |
|
|
|
|
|
|
|
if (!isTagt || ignoreTagt) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
if (currentElementData == null) { |
|
|
|
if (currentElementData == null) { |
|
|
|
currentElementData = new StringBuilder(); |
|
|
|
currentElementData = new StringBuilder(); |
|
|
|
} |
|
|
|
} |
|
|
|