Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datacollector
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenweisong
datacollector
Commits
b0b6a290
Commit
b0b6a290
authored
Apr 21, 2020
by
chenweisong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
2fffa518
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
70 deletions
+31
-70
DataFileUtil.java
...in/java/com/keymobile/rest/common/utils/DataFileUtil.java
+30
-70
TemplateController.java
...ava/com/keymobile/rest/controller/TemplateController.java
+1
-0
No files found.
src/main/java/com/keymobile/rest/common/utils/DataFileUtil.java
View file @
b0b6a290
...
...
@@ -18,82 +18,42 @@ import java.util.regex.Pattern;
public
class
DataFileUtil
{
p
rivate
static
final
String
fileName
=
"D:\\workspace\\record-demo\\origin\\补录系统excel拆分java代码\\数据和模板文件\\excel拆分导入文件2.txt"
;
p
ublic
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
// XSSFWorkbook book;
// XSSFSheet sheet;
// JSONArray jsons;
// XSSFRow row;
//
// try {
// InputStream is = new FileInputStream(new File("D:\\workspace\\record-demo\\origin\\补录系统excel拆分java代码\\数据和模板文件\\excel拆分导入文件.xlsx"));
//
// book = new XSSFWorkbook(is);
//
// sheet = book.getSheetAt(0);
//
// jsons = new JSONArray();
// for (int i = 1; i < sheet.getLastRowNum(); i++) {
// row = sheet.getRow(i);
// if (row != null) {
// JSONObject json = new JSONObject();
// //对于纯数字内容要做这一操作
// row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
// row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
// row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
// json.put("进程数", row.getCell(0).getStringCellValue());
// json.put("基准板", row.getCell(1).getStringCellValue());
// json.put("优化比", row.getCell(2).getStringCellValue());
// jsons.add(json);
// }
// }
//
// System.out.println(jsons.toJSONString());
// book.close();
// } catch (FileNotFoundException e) {
// // TODO 自动生成的 catch 块
// e.printStackTrace();
// } catch (IOException e) {
// // TODO 自动生成的 catch 块
// e.printStackTrace();
// }
File
file
=
new
File
(
fileName
);
List
objects
=
new
ArrayList
();
int
dataAt
=
3
;
//读取文件
BufferedReader
br
=
null
;
StringBuffer
sb
=
null
;
XSSFWorkbook
book
;
XSSFSheet
sheet
;
JSONArray
jsons
;
XSSFRow
row
;
try
{
br
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
file
),
"utf-8"
));
//这里可以控制编码
sb
=
new
StringBuffer
();
String
line
=
null
;
int
count
=
0
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
count
++;
if
(
count
<
dataAt
)
{
continue
;
}
sb
.
append
(
line
);
String
[]
data
=
line
.
toString
().
split
(
"\\s+"
);
objects
.
add
(
data
);
}
}
catch
(
Exception
e
)
{
InputStream
is
=
new
FileInputStream
(
new
File
(
"D:\\workspace\\record-demo\\origin\\补录系统excel拆分java代码\\数据和模板文件\\excel拆分导入文件.xlsx"
));
book
=
new
XSSFWorkbook
(
is
);
sheet
=
book
.
getSheetAt
(
0
);
jsons
=
new
JSONArray
();
for
(
int
i
=
1
;
i
<
sheet
.
getLastRowNum
();
i
++)
{
row
=
sheet
.
getRow
(
i
);
if
(
row
!=
null
)
{
JSONObject
json
=
new
JSONObject
();
//对于纯数字内容要做这一操作
row
.
getCell
(
0
).
setCellType
(
Cell
.
CELL_TYPE_STRING
);
row
.
getCell
(
1
).
setCellType
(
Cell
.
CELL_TYPE_STRING
);
row
.
getCell
(
2
).
setCellType
(
Cell
.
CELL_TYPE_STRING
);
json
.
put
(
"进程数"
,
row
.
getCell
(
0
).
getStringCellValue
());
json
.
put
(
"基准板"
,
row
.
getCell
(
1
).
getStringCellValue
());
json
.
put
(
"优化比"
,
row
.
getCell
(
2
).
getStringCellValue
());
jsons
.
add
(
json
);
}
}
System
.
out
.
println
(
jsons
.
toJSONString
());
book
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO 自动生成的 catch 块
e
.
printStackTrace
();
}
finally
{
try
{
br
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
IOException
e
)
{
// TODO 自动生成的 catch 块
e
.
printStackTrace
();
}
}
}
public
static
Object
convertDatToJson
(
MultipartFile
file
,
int
dataAt
)
{
List
ArrList
=
new
ArrayList
();
//读取文件
...
...
@@ -175,7 +135,7 @@ public class DataFileUtil {
*
* @param file
*/
public
static
void
delteTempFile
(
File
file
)
{
public
static
void
del
e
teTempFile
(
File
file
)
{
if
(
file
!=
null
)
{
File
del
=
new
File
(
file
.
toURI
());
del
.
delete
();
...
...
src/main/java/com/keymobile/rest/controller/TemplateController.java
View file @
b0b6a290
...
...
@@ -129,6 +129,7 @@ public class TemplateController {
@PostMapping
(
value
=
"/excel/getDatData"
)
public
Object
getDatData
(
MultipartFile
file
,
int
dataAt
)
{
CommonValidator
.
notNull
(
file
,
"文件不能为空"
);
CommonValidator
.
notLessThan
(
dataAt
,
0
,
"dataAt不能小于0"
);
return
DataFileUtil
.
convertDatToJson
(
file
,
dataAt
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment