社区
Web 开发
帖子详情
excel文件转换成二进制文件
windowboy
2008-10-06 04:43:09
大家好,请问怎么把一个二进制的文件转换成excel文件,把一个excel文件转换成二进制文件。
...全文
721
5
打赏
收藏
excel文件转换成二进制文件
大家好,请问怎么把一个二进制的文件转换成excel文件,把一个excel文件转换成二进制文件。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhangsf1982
2008-10-06
打赏
举报
回复
将二进制数据从数据库读出 产生excel文件
//masterObject=home.getCase(helpDeskNo);
int seq=hr.getInt("seq");
String fileName=hr.getString("filename");
// CaseAttachmentHome attachHome= HomeFactory.getCaseAttachmentHome(con);
// CaseAttachment attachment=attachHome.getCaseAttachment(helpDeskNo,seq);
// if(!attachment.getFileName().equals(fileName))return;
java.sql.PreparedStatement pstmt = null;
OutputStream fileOut=null;
String SQL = null;
Pageable rs = null;
SQL="SELECT FILE_CONTENT FROM dbo.CASE_ATTACHMENT WHERE HELPDESK_NO=? and SEQ_NO=? ";
try {
int id=1;
pstmt = con.prepareStatement(SQL);
pstmt.setString(id++, helpDeskNo);
pstmt.setInt(id++, seq);
rs = (Pageable) pstmt.executeQuery();
if(rs.getRowsCount()==0) throw new CaseAttachmentNotFoundException(this);
rs.first();
InputStream fc = rs.getBinaryStream("FILE_CONTENT");
log.info("size="+fc.available());
response.reset();
response.setContentType("application/x-download");
response.addHeader(
"Content-Disposition",
"attachment; filename=" + fileName);
byte[] b = new byte[fc.available()];
int rec =0;
// OutputStream sout = new FileOutputStream(fileName);
ServletOutputStream sout = response.getOutputStream();
// w fc.read(b,0,b.length);
// w sout.write(b);
while ((rec = fc.read(b)) > 0) {
sout.write(b,0,rec);
}
// w while(fc.read(b)!=-1){
// w fileOut.write(b);
// w }
// fileOut.close();
sout.close();
fc.close();
rs.close();
// fileOut = new FileOutputStream(fileName);
// byte[] idata = new byte[8000];
//
// response.setCharacterEncoding("utf-8");
// response.setContentType("application/x-download");
// response.addHeader("Accept-Ranges", "bytes");
// response.addHeader("Accept-Length", "" + fc.available());
// response.addHeader(
// "Content-Disposition",
// "attachment; filename=" + fileName);
//
// int rec =0;
// while ((rec = fc.read(idata)) > 0) {
// fileOut.write(idata,0,rec);
// }
//// while(fc.read(idata)!=-1){
//// fileOut.write(idata);
//// }
//
// idata = null;
// fileOut.flush();
// fileOut.close();
// fc.close();
}
catch (SQLException sqle) {
//to do
System.err.println("Error : " + sqle);
sqle.printStackTrace();
throw sqle;
}
finally {
try {rs.close();} catch (Exception e) {}
try {pstmt.close();} catch (Exception e) {}
try {fileOut.close();} catch (Exception e) {}
}
zhangsf1982
2008-10-06
打赏
举报
回复
private void insertIt() throws FileNotFoundException,java.sql.SQLException {
java.sql.Connection con = null;
java.sql.PreparedStatement pstmt = null;
String SQL = null;
FileInputStream fin=null;
SQL="INSERT INTO dbo.CASE_ATTACHMENT (HELPDESK_NO, SEQ_NO, FILE_NAME,FILE_CONTENT, CREATED_BY, CREATED_DATE ) VALUES (?, ?, ?, ?, ?, ? )";
try {
File f = new File(ContentFileName);
fin = new FileInputStream(f);
int len = (int)f.length();
con = getCon();
int id=1;
pstmt = con.prepareStatement(SQL);
pstmt.setString(id++, HelpdeskNO);
SeqNO=getNextSeqNO();
pstmt.setInt(id++, SeqNO);
pstmt.setString(id++, f.getName());
pstmt.setBinaryStream(id++, fin,len);
pstmt.setString(id++, CreatedBy);
if(CreatedDate!=null)
pstmt.setTimestamp(id++, CreatedDate.getSQLTimestamp());
else
pstmt.setTimestamp(id++, null)
;
int iAffected = pstmt.executeUpdate();
//to do
commit();
setIsNew(false);
}
catch (SQLException sqle) {
try {
//if you need..
rollback();
}
catch (Exception e) {}
System.err.println("Error : " + sqle);
sqle.printStackTrace();
throw sqle;
}
finally {
try {pstmt.close();} catch (Exception e) {}
try {closeCon();} catch (Exception e) {}
try{ fin.close();}catch(Exception e){}
}
}
此Function 是将文件"ContentFileName" 以二进制存入数据库
wunan320
2008-10-06
打赏
举报
回复
excel一般是一个字段记录位置,一个字段记录长度,一个字段记录内容,把这些转换成二进制,最后一起生成一个文件即可.
jabeginner
2008-10-06
打赏
举报
回复
可用一般的fread,fwrite,fopen或FileCreate,FileRead,FileWrite即可。
先读出Excel中的内容,然后写文件。
zhj92lxs
2008-10-06
打赏
举报
回复
.
Excel
转
二进制
工具
首先,我们要理解为何需要将
Excel
转换为
二进制
文件
。
Excel
的数据结构在内存中并不直接适用于游戏引擎,它需要经过解析才能被游戏代码读取。
二进制
文件
则可以提供更快的读取速度和更小的存储空间,特别适合游戏运行时...
Unity/C#的
Excel
转
二进制
和XML工具
例如,开发者可以将角色的各种属性(生命值、攻击力、防御力等)存储在
Excel
中,然后转换为
二进制
文件
,在游戏启动时一次性加载,或者根据需要动态加载,以提高游戏性能。 总的来说,"Unity/C#的
Excel
转
二进制
和XML...
二进制
文件
转换成
文本
文件
这是一段小程序,功能是将
二进制
文件
(*.dat)
转换成
文本
文件
(或者
Excel
表格)!
excel
转
二进制
文件
以及代码源码
总结来说,"
Excel
转
二进制
文件
"是一种优化
Excel
文件
处理性能的方法,尤其适合大数据量的应用场景。通过编程语言实现这个转换,我们可以利用现有的库如pandas和EPPlus,结合源码分析,创建自己的转换工具。提供的...
excel
二进制
格式
Excel
二进制
格式,主要指的是Microsoft
Excel
的一种存储方式,它以
二进制
文件
(BINARY FILE FORMAT,简称BIFF)的形式保存数据。这种格式在早期版本的
Excel
中就已经出现,并一直沿用到现代版本,特别是在
Excel
97到...
Web 开发
81,122
社区成员
341,744
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章