通过文件结构直接生成xls文件 java

来源:互联网 发布:华为网络盒子评测 编辑:程序博客网 时间:2024/05/14 00:21
  1. 不错,我改成了Java版:
  2. import java.io.*;
  3. public class MakeExcel {
  4. public MakeExcel() {
  5. }
  6. public static void main(String[] args) {
  7. File file = null;
  8. FileOutputStream fos = null;
  9. try {
  10. file = new File("test.xls");
  11. file.createNewFile();
  12. fos = new FileOutputStream(file);
  13. short[] header = new short[] {0x809800x1000};
  14. short[] end = new short[] {0xa0};
  15. for (byte i = 0; i < header.length; i++) {
  16. fos.write(short2bytes(header[i]));
  17. }
  18. writeNumber(fos, (short4, (short440.5);
  19. writeString(fos, (short10, (short10"中文测试");
  20. for (byte i = 0; i < end.length; i++) {
  21. fos.write(short2bytes(end[i]));
  22. }
  23. fos.close();
  24. catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. static void writeString(FileOutputStream fos, short x, short y,
  29. String s) {
  30. try {
  31. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  32. DataOutputStream dos = new DataOutputStream(baos);
  33. dos.write((new String(s.getBytes("utf-8"), "utf-8")).getBytes());
  34. dos.close();
  35. baos.close();
原创粉丝点击