在我的Maven项目中,我在src/main/resources中有一个xls文件.我这样读的时候:
InputStream in = new
FileInputStream("src/main/resources/WBU_template.xls");
Run Code Online (Sandbox Code Playgroud)
一切都好.
但是我想用getResourceAsStream将其作为InputStream读取.当我这样做时,无论有没有斜线,我总是得到一个NPE.
private static final String TEMPLATEFILE = "/WBU_template.xls";
InputStream in = this.getClass.getResourceAsStream(TEMPLATEFILE);
Run Code Online (Sandbox Code Playgroud)
无论是否存在斜杠,或者如果我使用了getClassLoader()方法,我仍然会得到一个NullPointer.
我也试过这个:
URL u = this.getClass().getResource(TEMPLATEFILE);
System.out.println(u.getPath());
Run Code Online (Sandbox Code Playgroud)
控制台说.../target/classes/WBU_template.xls然后得到我的NullPointer.
我究竟做错了什么 ?
电子表格仍会显示,但会显示警告消息.问题似乎发生,因为Excel 2007对于匹配其扩展的格式比早期版本的Excel更加挑剔.
该问题最初是由ASP.Net程序发现的,并在Excel错误中产生"您尝试打开的文件",Spreadsheet.aspx-18.xls',其格式与文件扩展名指定的格式不同.验证...".但是,当我打开文件时它显示正常.我正在使用Excel 2007.Firefox将该文件识别为Excel 97-2003工作表.
这是一个生成问题的ASP.NET页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Spreadsheet.aspx.cs" Inherits="Spreadsheet" %>
Run Code Online (Sandbox Code Playgroud)
文件背后的代码如下:
public partial class Spreadsheet : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/vnd.ms-excel";
Response.Clear();
Response.Write("Field\tValue\tCount\n");
Response.Write("Coin\tPenny\t443\n");
Response.Write("Coin\tNickel\t99\n");
}
Run Code Online (Sandbox Code Playgroud)
}
Ť
有没有人有任何样本Java代码将JSON文档转换为XLS/CSV文件?我试图在Google上搜索但无济于事.
我试图使用Microsoft.Office.Interop.Excel.Workbook类将.xls文件转换为服务器端的.xlsx文件,如下所示:
workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, …Run Code Online (Sandbox Code Playgroud) 我试图使用ExcelDataReader读取Ubuntu上的.xls文件.我正在使用VS#和C#.这是代码:
var stream = File.Open(filePath, mode: FileMode.Open, access: FileAccess.Read);
var reader = ExcelReaderFactory.CreateReader(stream);
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
var reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream);
Run Code Online (Sandbox Code Playgroud)
当我运行时,我收到以下异常:
未处理的异常:System.NotSupportedException:没有可用于编码的数据1252.有关定义自定义编码的信息,请参阅Encoding.RegisterProvider方法的文档.在System.Text.Encoding.GetEncoding(Int32代码页)
我已经安装了libmono-i18n-west4.0-cil(也试过libmono-i18n4.0-all),因为我发现有些人推荐这个,但问题仍然存在.还安装了包System.Text.Encoding.CodePages没有成功.
谁能帮忙解决这个问题?
我正在从文本文件中读取整数,将它们作为查询的输入并获取查询输出并写入xls文件.
ResultSet rs;
Connection con = null;
PreparedStatement ps = null;
int person_org_id, external_person_org_id;
File f = null;
Scanner scan = null;
try {
System.out.println("----------checkpoint-----------");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("----------checkpoint 1-----------");
con = DriverManager.getConnection("jdbc:oracle:thin:@ksdjf.kjdlk.jkd.com:2222:edb", "aaaaa", "aaaa");
System.out.println("----------checkpoint 2 ----------");
if (con == null) {
System.out.println("unable to connect to database");
}
System.out.println("----------checkpoint 3::connected to database---------");
StringBuffer sql = new StringBuffer();
sql.append("select abd from edb.abd where customer_id=510 and person_org_id =? ");
ps = con.prepareStatement(sql.toString());
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的Excel电子表格,我需要在iPhone应用程序中使用这些数据.xls文档有6列,> 200行.
我想从xls文档创建一个plist.如何以编程方式将一个转换为另一个?
任何人都可以指导我如何使用PHP将XLS转换为CSV?
我有excel电子表格,其中包含文档列表,我想使用PHP将其转换为CSV格式.
我想将它从一个数据库更改为另一个数据库.
在数据透视表上下文菜单上似乎没有任何选项可以执行此操作
我必须将算法从Excel工作表移植到python代码,但我必须从Excel文件中对算法进行反向工程.
Excel工作表非常复杂,它包含许多单元格,其中有公式引用其他单元格(也可以包含公式或常量).
我的想法是用python脚本分析构建一个单元格之间依赖关系的表格,即:
A1取决于B4,C5,E7公式:"= sqrt(B4)+ C5*E7"
A2取决于B5,C6公式:"= sin(B5)*C6"
......
所述xlrd蟒模块允许读取XLS工作簿但此刻我可以访问到的值的单元,而不是的公式.
例如,使用以下代码,我可以简单地得到一个单元格的值:
import xlrd
#open the .xls file
xlsname="test.xls"
book = xlrd.open_workbook(xlsname)
#build a dictionary of the names->sheets of the book
sd={}
for s in book.sheets():
sd[s.name]=s
#obtain Sheet "Foglio 1" from sheet names dictionary
sheet=sd["Foglio 1"]
#print value of the cell J141
print sheet.cell(142,9)
Run Code Online (Sandbox Code Playgroud)
无论如何,似乎没有办法从.cell(...)方法返回的Cell对象中获取formul .在文档中,他们说可以获得公式的字符串版本(英文版,因为没有关于存储在Excel文件中的函数名转换的信息).他们在Name和Operand类中谈论公式(表达式),无论如何我无法理解如何通过必须包含它们的Cell类实例来获取这些类的实例.
你能建议一个从单元格中获取公式文本的代码片段吗?