- 不错,我改成了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();
通过文件结构直接生成xls文件 java
最新推荐文章于 2023-08-04 11:06:15 发布