通过文件结构直接生成xls文件 java
2008-08-04 16:01
375 查看
不错,我改成了Java版:
import java.io.*;
public class MakeExcel {
public MakeExcel() {
}
public static void main(String[] args) {
File file = null;
FileOutputStream fos = null;
try {
file = new File("test.xls");
file.createNewFile();
fos = new FileOutputStream(file);
short[] header = new short[] {0x809, 8, 0, 0x10, 0, 0};
short[] end = new short[] {0xa, 0};
for (byte i = 0; i < header.length; i++) {
fos.write(short2bytes(header[i]));
}
writeNumber(fos, (short) 4, (short) 4, 40.5);
writeString(fos, (short) 10, (short) 10, "中文测试");
for (byte i = 0; i < end.length; i++) {
fos.write(short2bytes(end[i]));
}
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static void writeString(FileOutputStream fos, short x, short y,
String s) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write((new String(s.getBytes("utf-8"), "utf-8")).getBytes());
dos.close();
baos.close();
import java.io.*;
public class MakeExcel {
public MakeExcel() {
}
public static void main(String[] args) {
File file = null;
FileOutputStream fos = null;
try {
file = new File("test.xls");
file.createNewFile();
fos = new FileOutputStream(file);
short[] header = new short[] {0x809, 8, 0, 0x10, 0, 0};
short[] end = new short[] {0xa, 0};
for (byte i = 0; i < header.length; i++) {
fos.write(short2bytes(header[i]));
}
writeNumber(fos, (short) 4, (short) 4, 40.5);
writeString(fos, (short) 10, (short) 10, "中文测试");
for (byte i = 0; i < end.length; i++) {
fos.write(short2bytes(end[i]));
}
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static void writeString(FileOutputStream fos, short x, short y,
String s) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.write((new String(s.getBytes("utf-8"), "utf-8")).getBytes());
dos.close();
baos.close();
相关文章推荐
- 通过文件结构直接生成xls文件-Java版
- 通过文件结构直接生成xls文件的VB.Net和Java两个版本
- 通过文件结构直接生成xls文件的VB.Net和Java两个版本
- 直接通过excel可以识别的文件结构生成xls文件的方法,这样就可以不引用麻烦的ole了 (转)
- 通过excel可识别的xml结构直接生成xls文件
- 通过文件结构直接生成xls文件
- 通过文件结构直接生成xls文件
- 通过文件结构直接生成xls文件
- C# 通过文件结构直接生成xls(Excel)文件
- 通过文件结构直接生成xls文件
- 通过excel可识别的xml结构直接生成xls文件收藏
- 通过excel可识别的xml结构直接生成xls文件
- 通过excel可识别的xml结构直接生成xls文件
- 通过文件结构生成xls
- 通过Middlegen生成hbm文件和java代码
- Java通用的Excel文件生成工具类,支持生成文件和浏览器直接下载(未测试)
- 获取文件夹大小的java类,通过类名调用方法,可直接获取文件大小
- Java通过XML字符串生成XML物理文件
- java解析dbf之通过javadbf包生成和读取dbf文件
- Java通用的Excel文件生成工具类,支持生成文件和浏览器直接下载