- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从技术上讲,我知道如何使用工作表创建 xls。但我在为 Excel 中的每个工作表创建目录时遇到问题。
示例位于此消息下方。正如您所看到的,有一个工作表名称和具有相应工作表名称的行(例如 Sheet1、Sheet2)。是否还有一种可能的语法可以将 Sheet1 链接到 Sheet1 ?
谢谢
最佳答案
您的屏幕截图显示的是 HyperlinkType.DOCUMENT 类型的超链接。 https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ 中有一个 HyperlinkExample.java
。还演示了如何创建指向同一工作簿中的目标工作表和单元格的超链接。
要创建屏幕截图显示的内容,您还需要了解的是:
创建工作簿、工作表、行和单元格。设置单元格内容。设置自动过滤。设置列宽。
这一切都显示在 Busy Developers' Guide to HSSF and XSSF Features 中。其中大部分的完整示例也在 https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ 中和/或 https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/ .
完全创建屏幕截图所示内容的完整示例:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
class CreateExcelLinkedSheetsTOC {
public static void main(String[] args) throws Exception {
try (
Workbook workbook = new XSSFWorkbook();
FileOutputStream fileout = new FileOutputStream("./Excel.xlsx")
//Workbook workbook = new HSSFWorkbook();
//FileOutputStream fileout = new FileOutputStream("./Excel.xls")
) {
// we need creation helber for creating the links
CreationHelper creationHelper = workbook.getCreationHelper();
// hyperlink cell style
CellStyle hlink_style = workbook.createCellStyle();
Font hlink_font = workbook.createFont();
hlink_font.setUnderline(Font.U_SINGLE);
hlink_font.setColor(IndexedColors.BLUE.getIndex());
hlink_style.setFont(hlink_font);
// create 6 sheets
Sheet sheet = null;
for (int i = 1; i < 7; i++) {
sheet = workbook.createSheet("Sheet" + i);
}
// create sheet "Source" as the 7th sheet
sheet = workbook.createSheet("Source");
// create sheet "Table of Contents"
sheet = workbook.createSheet("Table of Contents");
// unselect first sheet
workbook.getSheetAt(0).setSelected(false);
// make "Table of Contents" the new first sheet
workbook.setSheetOrder("Table of Contents", 0);
// make "Table of Contents" the active sheet
workbook.setActiveSheet(0);
// create header row
Row row = sheet.createRow(0);
Cell cell = row.createCell(1);
cell.setCellValue("#");
cell = row.createCell(2);
cell.setCellValue("Sheet Name");
// create content rows
String sheetName = "";
Hyperlink link = null;
int numberOfSheets = workbook.getNumberOfSheets();
for (int i = 1; i < numberOfSheets; i++) {
row = sheet.createRow(i);
cell = row.createCell(1);
cell.setCellValue(i);
cell = row.createCell(2);
sheetName = workbook.getSheetName(i);
cell.setCellValue(sheetName);
// create hyperlink to cell A1 in sheet with sheetName
link = creationHelper.createHyperlink(HyperlinkType.DOCUMENT);
link.setAddress("'" + sheetName + "'!A1");
cell.setHyperlink(link);
// style the link cell
cell.setCellStyle(hlink_style);
}
// set AutoFilter as shown in image
sheet.setAutoFilter(new CellRangeAddress(
0, numberOfSheets-1, 1, 2)
);
// set column widths
sheet.setColumnWidth(0, 5 * 256);
sheet.setColumnWidth(1, 5 * 256);
sheet.setColumnWidth(2, 15 * 256);
workbook.write(fileout);
}
}
}
关于java - 使用目录创建 excel 文件 Spring boot java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60053048/
我正在为我的程序编写安装脚本,它应该在 Linux/Unix 操作系统上运行。以下文件的默认目录是什么: 可执行文件(程序)。程序应通过从命令行键入其名称来执行。 共享库。 第三方共享库(程序未开源,
我有一堆用户、组和应用程序注册,我的 MVC 应用程序使用 AAD 数据进行身份验证和授权。是否可以将 Azure Active Directory 从一个租户(目录)迁移到另一个租户(目录)?如果可
查看 cljsbuild 文档 https://github.com/emezeske/lein-cljsbuild :cljsbuild { :builds [{ ; The
忽略已经版本控制的文件 如果你不小心添加了一些应该被忽略的文件,你如何将它们从版本控制中去除而不会丢失它们?或许你有自己的IDE配置文件,不是项目的一部分,但将会花费很多时间使之按照自己的方式工作。
我想使用\tableofcontents 命令,但没有目录从新页面开始或在末尾创建新页面,并且所有内容都是单倍行距。我怎样才能做到这一点?我假设使用 tocloft,但有哪些选择? 谢谢 最佳答案 试
我有一些 javascript 菜单代码,可以在单独的目录中正常工作。但是,当我尝试从同一目录中调用相同的 .js 文件时,它不会看到这些文件。 以下内容来自另一个目录: script type="t
我有这样的路径: /my/path/to/important_folder 在同一级别上,我还有其他文件和文件夹想要在达到与 important_folder 相同的级别时列出。 我的文件夹可能更深,
1、获取文件路径实现 1.1 获取当前文件路径 ? 1
我正在使用最新版本的 NTEmacs。 我写了一个名为“.dir-locals.el”的文件,如下所示。 ((nil . ((tab-width . 8) (fill-column .
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
在我的 .vimrc 中有这些行 :set foldmethod=marker :set foldmarker=SECTION:,ENDSECTION: 用于自定义代码折叠。在我的文件中,相关语言的注
在 fish 中: for x in * echo $x end *这里包括所有目录和文件,如何只列出文件(或目录)? 最佳答案 fish 没有很多花哨的通配语法。但是,目录可以像这样迭代: f
这是我的目录结构: ├── src │ ├── helpers │ │ ├── __init__.py │ │ ├── foo.py │ │ └── bar.py │
我想递归重命名文件夹/目录名称并找到 this solution所以。但是这个命令没有效果 find . -type f -exec rename 's/old/new/' '{}' \; 这是一个正
我想在相册中创建一个文件夹,并希望将图像保存在创建的相册中。 这可能吗?有什么办法可以做到这一点吗? 我已经搜索过,大多数人都说这是不可能的。 感谢您的帮助。 最佳答案 您也许可以使用AssetsLi
如何在python中使用用户定义的名称创建临时文件/目录。我知道 tempfile .但是我看不到任何以文件名作为参数的函数。 注意:我需要这个来对包含临时文件的临时目录上的 glob(文件名模式匹配
我在项目中使用JaCoCo Gradle插件。 作为问题的一个示例,我的大部分代码都在com.me.mysoftware包下。 我正在使用代码生成器来生成build/generated/java/..
我正在尝试使用 Gradle 开始运行 jar 文件 我的任务如下所示: task startServer(type: Exec) { workingDir file("${buildDir}/a
如何在 Ant 中定义一个目录集,其中包括两个目录:项目的基目录和子目录“test”? 看起来您无法使用“/”、“.”或“”专门包含目录集的根目录。例如,这包括“./test”,但不包括“.”:
我正在使用 CTAGs 包,它使用 Sublime Text 2 生成两个文件 .tags 和 .tags_sorted_by_file。 那么当我进行项目搜索(CMD + SHIFT + F)时,如
我是一名优秀的程序员,十分优秀!