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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
69 deletions
+30
-69
DataFileUtil.java
...in/java/com/keymobile/rest/common/utils/DataFileUtil.java
+29
-69
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,80 +18,40 @@ import java.util.regex.Pattern;
...
@@ -18,80 +18,40 @@ import java.util.regex.Pattern;
public
class
DataFileUtil
{
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
)
{
XSSFWorkbook
book
;
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
XSSFSheet
sheet
;
JSONArray
jsons
;
// XSSFWorkbook book;
XSSFRow
row
;
// 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
;
try
{
try
{
br
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
file
),
"utf-8"
));
//这里可以控制编码
InputStream
is
=
new
FileInputStream
(
new
File
(
"D:\\workspace\\record-demo\\origin\\补录系统excel拆分java代码\\数据和模板文件\\excel拆分导入文件.xlsx"
));
sb
=
new
StringBuffer
();
book
=
new
XSSFWorkbook
(
is
);
String
line
=
null
;
sheet
=
book
.
getSheetAt
(
0
);
int
count
=
0
;
jsons
=
new
JSONArray
();
while
((
line
=
br
.
readLine
())
!=
null
)
{
for
(
int
i
=
1
;
i
<
sheet
.
getLastRowNum
();
i
++)
{
count
++;
row
=
sheet
.
getRow
(
i
);
if
(
count
<
dataAt
)
{
if
(
row
!=
null
)
{
continue
;
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
);
}
}
sb
.
append
(
line
);
String
[]
data
=
line
.
toString
().
split
(
"\\s+"
);
objects
.
add
(
data
);
}
}
System
.
out
.
println
(
jsons
.
toJSONString
());
}
catch
(
Exception
e
)
{
book
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO 自动生成的 catch 块
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// TODO 自动生成的 catch 块
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
try
{
br
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
public
static
Object
convertDatToJson
(
MultipartFile
file
,
int
dataAt
)
{
public
static
Object
convertDatToJson
(
MultipartFile
file
,
int
dataAt
)
{
...
@@ -175,7 +135,7 @@ public class DataFileUtil {
...
@@ -175,7 +135,7 @@ public class DataFileUtil {
*
*
* @param file
* @param file
*/
*/
public
static
void
delteTempFile
(
File
file
)
{
public
static
void
del
e
teTempFile
(
File
file
)
{
if
(
file
!=
null
)
{
if
(
file
!=
null
)
{
File
del
=
new
File
(
file
.
toURI
());
File
del
=
new
File
(
file
.
toURI
());
del
.
delete
();
del
.
delete
();
...
...
src/main/java/com/keymobile/rest/controller/TemplateController.java
View file @
b0b6a290
...
@@ -129,6 +129,7 @@ public class TemplateController {
...
@@ -129,6 +129,7 @@ public class TemplateController {
@PostMapping
(
value
=
"/excel/getDatData"
)
@PostMapping
(
value
=
"/excel/getDatData"
)
public
Object
getDatData
(
MultipartFile
file
,
int
dataAt
)
{
public
Object
getDatData
(
MultipartFile
file
,
int
dataAt
)
{
CommonValidator
.
notNull
(
file
,
"文件不能为空"
);
CommonValidator
.
notNull
(
file
,
"文件不能为空"
);
CommonValidator
.
notLessThan
(
dataAt
,
0
,
"dataAt不能小于0"
);
return
DataFileUtil
.
convertDatToJson
(
file
,
dataAt
);
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