【异常解决】jxl.write.biff.JxlWriteException: Attempt to modify a referenced format

一般用jxl在插入单元格内容之前都需要对ceil进行各种各样的样式设置,比如以下的:

WritableFont font1 = new WritableFont(WritableFont.TIMES, 12,
					WritableFont.BOLD);
			WritableCellFormat formatTitle = new WritableCellFormat(font1);// 表头样式
			formatTitle.setBorder(jxl.format.Border.ALL,
					jxl.format.BorderLineStyle.THIN);
			formatTitle.setAlignment(jxl.format.Alignment.CENTRE);
			WritableCellFormat formatCeil = new WritableCellFormat();// 非表头样式
			formatCeil.setAlignment(jxl.format.Alignment.CENTRE);
			formatCeil.setBorder(jxl.format.Border.ALL,
					jxl.format.BorderLineStyle.THIN);

然后后面就用这两个对象进行插入的时候重用样式,比如:

Label titel0 = new Label(0, 0, "日期", formatTitle);// (列,行,值)
wsheet0.addCell(titel0);

今天遇到一个问题,就是想要在原来的样式对象的基础上进行增量修改的,再对某一些单元格进行插入,我们很理所当然地会想到以下的写法:

//在新的对象上增量设置,减少代码冗余
WritableCellFormat newFormat=formatTitle4sheet3;//下单错误统计头橙色
			newFormat.setBackground(Colour.ORANGE);

可是,本应该“理所当然”正确运行的代码却发生了异常:

jxl.write.biff.JxlWriteException: Attempt to modify a referenced format
    at jxl.write.biff.CellXFRecord.setBackground(CellXFRecord.java:100)
    at jxl.write.WritableCellFormat.setBackground(WritableCellFormat.java:192)
    at jxl.write.WritableCellFormat.setBackground(WritableCellFormat.java:180)
后来查阅资料得知,已经被引用了的WritableCellFromat对象是不可以再修改的,否则就报以上的错了。大概是处于安全的考虑...

将代码冗余地再重新设置一遍,将上面定义表头样式的句子和增量的样式定义,啰嗦地重写一遍,对象名字重新取一下就可以了,相信大家不需要再看这么无聊的代码了吧,就不贴了。

然后运行就正常了。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
How to be a Programmer: Community Version Robert L. Read with Community Copyright 2002, 2003, 2016 Robert L. Read Licensed under Creative Commons Attribution-ShareAlike 4.0 International License. Available on gitbook to read online or download for offline reading (as PDF, ePub or Mobi) Available to buy as a hardcover book (cost covers production & shipping only) - Edition 1, published 04/01/16 Introduction To be a good programmer is difficult and noble. The hardest part of making real a collective vision of a software project is dealing with one's coworkers and customers. Writing computer programs is important and takes great intelligence and skill. But it is really child's play compared to everything else that a good programmer must do to make a software system that succeeds for both the customer and myriad colleagues for whom he or she is partially responsible. In this essay I attempt to summarize as concisely as possible those things that I wish someone had explained to me when I was twenty-one. This is very subjective and, therefore, this essay is doomed to be personal and somewhat opinionated. I confine myself to problems that a programmer is very likely to have to face in her work. Many of these problems and their solutions are so general to the human condition that I will probably seem preachy. I hope in spite of this that this essay will be useful. Computer programming is taught in courses. The excellent books: The Pragmatic Programmer [Prag99], Code Complete [CodeC93], Rapid Development [RDev96], and Extreme Programming Explained [XP99] all teach computer programming and the larger issues of being a good programmer. The essays of Paul Graham [PGSite] and Eric Raymond [Hacker] should certainly be read before or along with this article. This essay differs from those excellent works by emphasizing social problems and comprehensively summarizing the entire set of necessary skills as I see them. In this essay the term boss is used to refer to whomever gives you projects to do. I use the words business, company, and tribe, synonymously except that business connotes moneymaking, company connotes the modern workplace and tribe is generally the people you share loyalty with. ---------------------------------------------------- 本 PDF 基于开源文档,目录书签齐全。 版权归原作者。 ---------------------------------------------------- Welcome to the tribe.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值