您的位置:首页 > 编程语言 > Java开发

通过文件结构直接生成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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: