我实现了Microsoft Excel文件的上传服务,无法确定上传了哪种文件.有时用户上传包含xlsx内容的xls扩展名的文件.要解析我使用Apache Poi的文件,目前我首先尝试将上传的文件解析为HSSFWorkbook,如果我发现异常,那么我尝试创建一个XSSFWorkbook.
有没有更聪明的方法来检测需要什么版本?
/** should parse the uploaded file */
private void handleUpload(File file) {
Workbook wb = tryToHandleHSSF(file);
if (wb==null)
wb = tryToHandleXSSF(file);
if (wb!=null) {
// ... do the parsing stuff
}
}
/** helper for HSSF */
private Workbook tryToHandleHSSF(File file) {
try {
return new HSSFWorkbook(new FileInputStream(file));
}
catch(Exception e) {
return null;
}
}
/** helper for XSSF */
private Workbook tryToHandleXSSF(File file) {
Workbook workbook;
try {
InputStream fin = new FileInputStream(file);
BufferedInputStream …Run Code Online (Sandbox Code Playgroud) 所以在下面的代码集中,由于某种原因,我得到了完全错误的答案......
import java.util.*;
import java.io.*;
import java.lang.*;
import type.lib.*;
public class Check03B
{
public static void main(String[] args)
{
PrintStream print = new PrintStream(System.out);
Scanner scan = new Scanner(System.in);
print.printf("Enter the satellite altitude in km ... ");
double A = scan.nextDouble();
double K = 0.00995;
double R = 6378;
double z = (K * (A + R));
double P = Math.pow(z,(3 / 2));
double x = (P / 3600);
double y = (P / 60);
print.printf("Orbital period = " + …Run Code Online (Sandbox Code Playgroud) 我只看到LineChart并Scatter Charts默认支持Apache POI.
问题: 如何在spreadhsheet中添加其他图表类型..
任何想法或任何帮助?或者是否有任何理由让apache只支持这两种类型的图表.
我有一个单元测试,它使用Elasticsearch的集成测试框架.使用Elasticsearch 2.0.0-2.1.2执行时工作正常,但是当我在IntelliJ中运行最新的Elasticsearch 2.2.0时,我得到以下内容,知道需要调整哪些不使用IntelliJ中的安全管理器?
java.security.AccessControlException: access denied ("org.elasticsearch.ThreadPermission" "modifyArbitraryThreadGroup")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at org.elasticsearch.SecureSM.checkThreadGroupAccess(SecureSM.java:166)
at org.elasticsearch.SecureSM.checkAccess(SecureSM.java:113)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
at java.lang.ThreadGroup.getParent(ThreadGroup.java:167)
at com.carrotsearch.randomizedtesting.Threads$2.run(Threads.java:127)
at com.carrotsearch.randomizedtesting.Threads$2.run(Threads.java:123)
at java.security.AccessController.doPrivileged(Native Method)
at com.carrotsearch.randomizedtesting.Threads.getTopThreadGroup(Threads.java:123)
at com.carrotsearch.randomizedtesting.Threads.getAllThreads(Threads.java:99)
at com.carrotsearch.randomizedtesting.ThreadLeakControl.<init>(ThreadLeakControl.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner.runSuite(RandomizedRunner.java:673)
at com.carrotsearch.randomizedtesting.RandomizedRunner.access$200(RandomizedRunner.java:140)
at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:591)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用页面工厂和页面对象模型运行Java项目,我想在Chrome,IE和Firefox上运行它,但是我无法在Firefox上运行它,浏览器没有打开,我得到了这个错误: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
我的代码是:
@BeforeMethod
public static void openBrowser() {
String browser = "";
if (browser.equalsIgnoreCase("chrome")){
System.setProperty("webdriver.chrome.driver", "src\\test\\Resources\\BrowserDrivers\\chromedriver.exe");
driver = new ChromeDriver();
}
else if (browser.equalsIgnoreCase("ie")){
System.setProperty("webdriver.ie.driver", "src\\test\\Resources\\BrowserDrivers\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
else {
driver = new FirefoxDriver();
}
driver = new FirefoxDriver();
driver.get("http://www.google.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@AfterMethod
public static void closeBrowser(){
driver.quit();
}
Run Code Online (Sandbox Code Playgroud) 我编写了应该创建 Excel 文件(xlsx 或 xls)并将自定义背景颜色设置为单元格的代码。创建 xls 文件时,背景颜色工作正常,但在 xlsx 的情况下,背景颜色未设置为正确的颜色。
我的代码有什么问题?
public class PoiWriteExcelFile {
static Workbook workbook;
static Sheet worksheet;
public static void main(String[] args) {
try {
String type = "xlsx"; //xls
FileOutputStream fileOut = new FileOutputStream("D:\\poi-test." + type);
switch (type) {
case "xls":
workbook = new HSSFWorkbook();
break;
case "xlsx":
workbook = new XSSFWorkbook();
break;
}
CellStyle cellStyle = workbook.createCellStyle();
switch (type) {
case "xls":
HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
palette.setColorAtIndex(HSSFColor.LAVENDER.index, (byte)128, (byte)0, (byte)128);
HSSFColor hssfcolor = palette.getColor(HSSFColor.LAVENDER.index); …Run Code Online (Sandbox Code Playgroud)