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

  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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值