Excel甘特图 Gantt Chart

基于Excel开发的甘特图,保留Excel的功能,单元格可嵌入各种公式,设置字体,颜色,背景

不需要Projector,比Projector更简单易用

具备节点标记,今日显示,大项任务突出显示,进度标识,状态颜色标识,周期计算,周末标记与隐藏,节假日自动识别(包括农历假期),自定义假期,自动统计各项任务的工作日和休息日天数(方便评估实际工作强度),按周按月分组等功能。

在这里插入图片描述

Java中可以使用Apache POI库来导出Excel表格,同时使用JavaFX的甘特图来生成数据。以下是一个示例代码: ```java import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.chart.CategoryAxis; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.StackedBarChart; import javafx.scene.chart.XYChart; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class GanttViewExportToExcel extends Application { @Override public void start(Stage primaryStage) throws Exception { // Create a category axis for the horizontal axis CategoryAxis xAxis = new CategoryAxis(); xAxis.setLabel("Tasks"); // Create a number axis for the vertical axis NumberAxis yAxis = new NumberAxis(); yAxis.setLabel("Time"); // Create a stacked bar chart StackedBarChart<String, Number> chart = new StackedBarChart<>(xAxis, yAxis); // Add the data to the chart XYChart.Series<String, Number> series1 = new XYChart.Series<>(); series1.setName("Task 1"); series1.getData().add(new XYChart.Data<>("Start", 0)); series1.getData().add(new XYChart.Data<>("End", 5)); XYChart.Series<String, Number> series2 = new XYChart.Series<>(); series2.setName("Task 2"); series2.getData().add(new XYChart.Data<>("Start", 1)); series2.getData().add(new XYChart.Data<>("End", 6)); XYChart.Series<String, Number> series3 = new XYChart.Series<>(); series3.setName("Task 3"); series3.getData().add(new XYChart.Data<>("Start", 2)); series3.getData().add(new XYChart.Data<>("End", 7)); chart.getData().addAll(series1, series2, series3); // Create a border pane to hold the chart BorderPane root = new BorderPane(); root.setCenter(chart); // Create a scene for the chart and add it to the stage Scene scene = new Scene(root, 600, 400); primaryStage.setScene(scene); // Export chart data to Excel exportToExcel(chart); primaryStage.show(); } private void exportToExcel(StackedBarChart<String, Number> chart) { // Create a new Excel workbook Workbook workbook = new XSSFWorkbook(); // Create a new sheet in the workbook Sheet sheet = workbook.createSheet("Gantt Chart"); // Add the data to the sheet int rowIndex = 0; for (XYChart.Series<String, Number> series : chart.getData()) { Row row = sheet.createRow(rowIndex++); row.createCell(0).setCellValue(series.getName()); CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); for (XYChart.Data<String, Number> data : series.getData()) { Cell cell = row.createCell(data.getXValue().hashCode() % 65536); cell.setCellValue(data.getYValue().doubleValue()); cell.setCellStyle(style); } } // Resize the columns in the sheet sheet.autoSizeColumn(0); for (int i = 1; i <= 100; i++) { sheet.setColumnWidth(i, 1000); } // Write the workbook to a file try (FileOutputStream outputStream = new FileOutputStream("GanttChart.xlsx")) { workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } } ``` 这个示例代码会创建一个包含三个任务的甘特图,并将数据导出到Excel表格中。你可以根据需要修改数据和文件名来创建自己的甘特图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值