mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-02 20:02:49 +08:00
fix csv bug
This commit is contained in:
parent
2d3d41c9f2
commit
d69b95f066
@ -33,7 +33,8 @@
|
||||
* 【core 】 修复UrlBuilder.of的query中含有?丢失问题(issue#I2CNPS@Gitee)
|
||||
* 【crypto 】 修复BCrypt.checkpw报错问题(issue#1377@Github)
|
||||
* 【extra 】 修复Fftp中cd失败导致的问题(issue#1371@Github)
|
||||
* 【core 】 修复Fftp中cd失败导致的问题(issue#1371@Github)
|
||||
* 【poi 】 修复ExcelWriter.merge注释问题(issue#I2DNPG@Gitee)
|
||||
* 【core 】 修复CsvReader读取注释行错误问题(issue#I2D87I@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -173,7 +173,6 @@ public final class CsvParser implements Closeable, Serializable {
|
||||
final Buffer buf = this.buf;
|
||||
int preChar = this.preChar;//前一个特殊分界字符
|
||||
int copyLen = 0; //拷贝长度
|
||||
boolean lineStart = true;
|
||||
boolean inComment = false;
|
||||
|
||||
while (true) {
|
||||
@ -201,15 +200,16 @@ public final class CsvParser implements Closeable, Serializable {
|
||||
final char c = buf.get();
|
||||
|
||||
// 注释行标记
|
||||
if(lineStart){
|
||||
if(preChar < 0 || preChar == CharUtil.CR || preChar == CharUtil.LF){
|
||||
// 判断行首字符为指定注释字符的注释开始,直到遇到换行符
|
||||
// 行首分两种,1是preChar < 0表示文本开始,2是换行符后紧跟就是下一行的开始
|
||||
if(c == this.config.commentCharacter){
|
||||
inComment = true;
|
||||
}
|
||||
lineStart = false;
|
||||
}
|
||||
// 注释行处理
|
||||
if(inComment){
|
||||
if ((c == CharUtil.CR || c == CharUtil.LF) && preChar != CharUtil.CR) {
|
||||
if (c == CharUtil.CR || c == CharUtil.LF) {
|
||||
// 注释行以换行符为结尾
|
||||
inComment = false;
|
||||
}
|
||||
@ -220,7 +220,7 @@ public final class CsvParser implements Closeable, Serializable {
|
||||
}
|
||||
|
||||
if (inQuotes) {
|
||||
//引号内,做为内容,直到引号结束
|
||||
//引号内,作为内容,直到引号结束
|
||||
if (c == config.textDelimiter) {
|
||||
// End of quoted text
|
||||
inQuotes = false;
|
||||
@ -295,10 +295,10 @@ public final class CsvParser implements Closeable, Serializable {
|
||||
* @param field 字段
|
||||
*/
|
||||
private void addField(List<String> currentFields, String field) {
|
||||
field = StrUtil.unWrap(field, config.textDelimiter);
|
||||
char textDelimiter = this.config.textDelimiter;
|
||||
final char textDelimiter = this.config.textDelimiter;
|
||||
field = StrUtil.unWrap(field, textDelimiter);
|
||||
field = StrUtil.replace(field, "" + textDelimiter + textDelimiter, textDelimiter + "");
|
||||
currentFields.add(StrUtil.unWrap(field, textDelimiter));
|
||||
currentFields.add(field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,9 +44,10 @@ public class CsvUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void readTest3() {
|
||||
CsvReader reader = CsvUtil.getReader();
|
||||
reader.read(FileUtil.getUtf8Reader("test.csv"), Console::log);
|
||||
reader.read(FileUtil.getUtf8Reader("d:/test/test.csv"), Console::log);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -683,7 +683,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
*
|
||||
* @param lastColumn 合并到的最后一个列号
|
||||
* @param content 合并单元格后的内容
|
||||
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式
|
||||
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式,只提取边框样式
|
||||
* @return this
|
||||
* @since 4.0.10
|
||||
*/
|
||||
@ -710,7 +710,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
* @param firstColumn 起始列,0开始
|
||||
* @param lastColumn 结束列,0开始
|
||||
* @param content 合并单元格后的内容
|
||||
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式
|
||||
* @param isSetHeaderStyle 是否为合并后的单元格设置默认标题样式,只提取边框样式
|
||||
* @return this
|
||||
* @since 4.0.10
|
||||
*/
|
||||
|
@ -498,4 +498,13 @@ public class ExcelWriteTest {
|
||||
writer.write(rows);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void formatTest(){
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx");
|
||||
final CellStyle cellStyle = writer.createCellStyle(0, 0);
|
||||
cellStyle.setDataFormat(writer.getWorkbook().createDataFormat().getFormat("yyyy-mm-dd"));
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user