commit a project on new repository

This commit is contained in:
石祥
2025-07-05 18:12:04 +08:00
parent ec1d12a068
commit f447320453
23 changed files with 1024 additions and 0 deletions

View File

@ -0,0 +1,6 @@
ports = []
[languages.java]
language = "java"
src_folder = "src/main/java/"
[languages.java.run]

69
JavaProject/pom.xml Normal file
View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>JavaProject</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>SpringBootProject</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 引入poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.17</version>
</dependency>
<!-- 引入swagger相关jar包 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,98 @@
package com.example.demo.controller;
public class ExcelConvertHtml {
public String static resolveExcel(MultipartFile file) throws Exception {
try {
File toFile = null;
if (file.equals("") || file.getSIze() <= 0) {
file = null;
} else {
InputStream ins = null;
ins = file.getInputStream():
toFile = new File(file.getOriginalFilename());
inputStreamToFile(ins, toFile);
ins.close();
}
// 获取数据
FileInputStream input = new FileInputStream(toFile);
Workbook workbook = new XSSFWorkbook(input);
Sheet sheet = workbook.getSheetAt(0);
// create html table
Element table = new Element(Tag.valueOf("table"), "");
table.attr("border", "1");
table.attr("cellspacing", "0");
table.attr("cellpadding", "0");
// Add column widths
Element colgroup = new Element(Tag.valueOf("colgroup"), "");
for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i++) {
Element col = new Element(Tag.valueOf("col"), "");
col.attr("width", "150px");// set column width
colgroup.appendChild(col);
}
table.appendChild(colgroup);
// Add header row
Element thead = new Element(Tag.valueOf("thread"), "");
Element tr = new Element(Tag.valueOf("tr"), "");
tr.attr("bgcolor", "#CCCCCC");
for (int i = 0; i < 2; i++) {
Cell cell = sheet.getRow(0).getCell(i);
String value = cell.getStringCellValue();
Element th = new Element(Tag.valueOf("th"), "");
th.text(value);
if (i == 0) {
// Merge first two columns
th.attr("colspan", "2");
}
tr.appendChild(th);
}
for (int i = 2; i < sheet,getRow(0).getLastCellNum();
i++){
Cell cell = sheet.getRow(0).getCell(i);
String value = cell.getStringCellValue();
Element th = new Element(Tag.valueOf("th"), "");
th.text(value);
tr.appendChild(th);
}
thread.appendChild(tr);
table.appendChild(thread);
// Add data rows
Element tbody = new Element(Tag.valueOf("tbody"), "");
// for (int i = 1; i <= sheet.getLastRowNum(); i++) {
// Element trData
// }
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Element trData = new Element(Tag.valueOf("tr"), "");
for (int j = 0; j < sheet.getRow(i).getLastCellNum(); j++) {
Cell cell = sheet.getRow(i).getCell(j);
String value = "";
if (cell.getCellType() == CellType.NUMERIC) {
value = String.valueOf(cell.getNumericCellValue());
} else {
value = cell.getStringCellValue();
}
Element td = new Element(Tag.valueOf("td"), "");
td.text(value);
if (j < 2) {
td.attr("align", "left");
}
trData.appendChild(td);
}
tbody.appendChild(trData);
}
table.appendChild(tbody); // Convert to HTML
Document doc = new Document("");
doc.appendChild(table);
String html = doc.outerHtml();
// Write to file
FileWriter writer = new FileWriter(new File("output.html"));
writer.write(html);
writer.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
}

View File

@ -0,0 +1,14 @@
package com.example.demo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Controller
@RestMapping
public class HelloController {
@GetMapping(value = "/")
public String index() {
return "Hello World!";
}
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,13 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ApplicationTests {
@Test
void contextLoads() {
}
}