二进制数据如何保存到excel文件中
发布网友
发布时间:2022-04-23 16:11
我来回答
共9个回答
热心网友
时间:2022-04-10 16:32
excel里面本来就有这种函数的:
HEX2BIN(number,places)
函数用不了,那就这样吧:
AB列中输入
48 0000
49 0001
50 0010
51 0011
52 0100
53 0101
54 0110
55 0111
56 1000
57 1001
65 1010
66 1011
67 1100
68 1101
69 1110
70 1111
你的十六进制数在C列,D1输入公式:
=VALUE(TEXT(VLOOKUP(CODE(MID(C1,1,1)),A$1:B$16,2),"0000")&TEXT(VLOOKUP(CODE(MID(C1,2,1)),A$1:B$16,2,FALSE),"0000"))
并将单元格数字格式设置为“0000 0000”,然后往下复制公式。
结果为:
AC 1010 1100
92 1001 0010
C7 1100 0111
FB 1111 1011
84 1000 0100
EB 1110 1011
EF 1110 1111
DB 1101 1011
F7 1111 0111
23 0010 0011
12 0001 0010
热心网友
时间:2022-04-10 17:50
二进制文件 打开二进制文件的语法格式如下:
Open pathname For Binary As [#]filenumber
说明: (1) 参数filename 和filenumber 分别表示文件名或文件号. (2)关键字Binary 表示打开的是二进制文件 (3)对于二进制文件,不能指定字节长度.每个打开的二进制文件都有一个自己的指针,文件指针是一个数字值,指向下一次读写操作的文件中的位置.二进制文件中的每个”位置”对应一个数据字节,因此,有n个字节的文件,就有1到n个位置. 我们可以用Seek()函数返回当前的文件指针位置(即下一个要读写的字节 );用Loc()函数返回上一次读写的字节位置,除非用Seek语句移动了指针,Loc()返回值总比Seek()的小1.我们来看下面的例子:
Open “student.txt” for Binary as #1
该语句用二进制的方式打开了student.txt文件.
你试试看
热心网友
时间:2022-04-10 19:25
你的意思是要把二进制代码反向转换成原来的excel文件?你是一下把你读出来的数据保存在一个扩展名为xlsb的文件里面,然后用excel去打开试一下,不过我想不行。但是我也没有更好的方法。
热心网友
时间:2022-04-10 21:16
将单元各设置为文本
热心网友
时间:2022-04-10 23:24
以下代码,在我的MySQL数据库中测试通过~
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* MySQL建表语句:create table test (id int primary key,xls blob)
*
*/
public class test {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
test t = new test();
t.insertXLS2DB(new File("D:\\test.xls"));
t.readXLSFromDB(new File("D:\\test2.xls"));
}
public void insertXLS2DB(File file) throws Exception{
FileInputStream fis = null;
Connection con = null;
PreparedStatement ps = null;
try {
fis = new FileInputStream(file);
con = getConnection();
con.setAutoCommit(false);
ps = con.prepareStatement("insert into test values(?,?)");
ps.setInt(1, 3);
ps.setBinaryStream(2,fis,fis.available());
ps.executeUpdate();
con.commit();
} catch (Exception e) {
if(con!=null)
con.rollback();
throw e;
}finally{
releaseResource(fis,ps,con);
}
}
public void readXLSFromDB(File f) throws Exception{
InputStream is = null;
FileOutputStream fos = null;
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
con = getConnection();
con.setAutoCommit(false);
ps = con.prepareStatement("select xls from test where id = ?");
ps.setInt(1, 3);
rs = ps.executeQuery();
if(!f.exists()){
f.createNewFile();
}
fos = new FileOutputStream(f);
while(rs.next()){
is = rs.getBinaryStream("xls");
}
con.commit();
byte[] bytes = new byte[1024];
int len = 0;
while((len=is.read(bytes))!=-1){
fos.write(bytes, 0, len);
}
fos.flush();
}catch(Exception e){
if(con!=null)
con.rollback();
throw e;
}finally{
releaseResource(is,fos,ps,con);
}
}
public Connection getConnection() throws SQLException{
return DriverManager.getConnection("jdbc:mysql://localhost:3306/pm?useUnicode=true&characterEncoding=UTF-8","root","gg");
}
public void releaseResource(Object... objs) throws IOException, SQLException{
for(Object obj:objs){
if(obj!=null){
if(obj instanceof Closeable){
((Closeable) obj).close();
}else if(obj instanceof Connection){
((Connection) obj).close();
}else if(obj instanceof Statement){
((Statement) obj).close();
}
}
}
}
}
热心网友
时间:2022-04-11 01:49
有必要吗
热心网友
时间:2022-04-11 04:30
如果你没找到合适的答案,把分给我吧。。。
我是混分的........................
热心网友
时间:2022-04-11 07:28
会有吧..
热心网友
时间:2022-04-11 10:43
应该会有吧..