首页 \ 问答 \ 使用Excel的库 - jxl?(Library for working with Excel - jxl?)

使用Excel的库 - jxl?(Library for working with Excel - jxl?)

jxl的可靠性和强大性如何? 我正在尝试从Java创建一个excel文件,执行合并单元格,创建图形,设置不同背景颜色(带渐变)等操作 - 基于我从用户收集的信息。 另外,我想用当前日期命名工作表并设置访问权限(只读或可编辑)。 我可以使用jxl完成所有这些吗?


How reliable and powerful is jxl? I'm trying to create an excel file from Java, performing operations like merging cells, creating graphs, setting different background colours (with gradients) - basing on information I collect from the user. Also, I would like to name sheets with current date and set access rights (read-only or editable). Can I do all this using jxl?


原文:https://stackoverflow.com/questions/9575810
更新时间:2023-01-01 16:01

最满意答案

我个人更喜欢这样的:

def self.parse(arg)
  key, value = arg.to_s.split(':')
  {
    'nil'     => new(nil), 
    'string'  => new(value),
    'boolean' => new(value == 'true'),
    'symbol'  => new(value.to_sym),
    'number'  => new(value.include?('.') ? BigDecimal(value) : Integer(value))
  }[key]
end

上面的代码实际上是2行,为了可读性分成多行。 但是,如果使用case是必须的,那么您可以将您的代码更改为:

def self.parse(arg)
  key, value = arg.to_s.split(':')
  case key
  when 'nil' then new(nil)
  when 'string' then new(value)
  when 'boolean' then new(value == 'true')
  when 'symbol' then new(value.to_sym)
  when 'number' then new(value.include?('.') ? BigDecimal(value) : Integer(value))
  end
end

I would personally prefer this:

def self.parse(arg)
  key, value = arg.to_s.split(':')
  {
    'nil'     => new(nil), 
    'string'  => new(value),
    'boolean' => new(value == 'true'),
    'symbol'  => new(value.to_sym),
    'number'  => new(value.include?('.') ? BigDecimal(value) : Integer(value))
  }[key]
end

Code above is actually of 2 lines, broken into multiple lines for readability sake. However, if using case is a must then you can change your code to this:

def self.parse(arg)
  key, value = arg.to_s.split(':')
  case key
  when 'nil' then new(nil)
  when 'string' then new(value)
  when 'boolean' then new(value == 'true')
  when 'symbol' then new(value.to_sym)
  when 'number' then new(value.include?('.') ? BigDecimal(value) : Integer(value))
  end
end

相关问答

更多
  • Midwire运行了一些基准测试并得出结论,如果/ elsif比情况更快,因为“隐式地使用更昂贵的===运算符进行比较”。 这是我得到这个报价的地方。 它比较/ elsif语句与case 。 这是非常彻底的,并探讨指令序列的差异,肯定会给你一个更好的想法。 我从帖子中拉出的主要内容是,如果if和else两者没有巨大差异,两者通常可以互换使用。 取决于您拥有多少个案例,可能会出现一些重大差异。 n = 1 (last clause matches) if: 7.4821e-07 three ...
  • 根据Ruby文档: case语句由一个可选条件组成,该条件位于case的参数位置,并且在子句时为零或更多。 匹配条件的第一个when子句(或者,如果条件为null,则评估为布尔真值)“wins”,并执行其代码节。 如果指定current_user作为大小写条件,那么将执行第一个匹配current_user表达式。 current_user.is_admin? 返回一个永远不会等于current_user的布尔值,所以你的第二个例子将总是采用else分支: case current_user when n ...
  • 当执行你的valid_handles查询时,这个结果是一个数组数组。 即使您只选择了一个列( SELECT twitter_handle FROM... ), valid_handles_results数组中的条目也是包含单个元素的数组。 所以要修复错误,用valid_handle[0].casecmp(record[1]) 虽然这看起来有点令人困惑,但背后的原因是这意味着@userDb.execute可以返回一致的结构,而不管查询中选择的列的数量是多少。 为了帮助调试将来的类似错误,了解“未定义的方法”错 ...
  • 我假定系统或最终用户在某个时刻有效地选择了文本类型,并且需要将其转换为要使用的类。 否则,您可以编写简单地引用并实例化正确类的调用代码。 你可以通过定义符号type和类之间的映射来使你更清晰。 所以你可以在create_account的范围内做到这一点: ACCOUNT_CLASS_FOR = Hash[ current: CurrentAccount, savings: SavingsAccount, business: BusinessAccount, ir: IRAcc ...
  • Ruby的case语句比大多数其他switch语句更灵活。 它使用===运算符,而不是==运算符。 类按照行定义===运算符 def ===(other)other.is_a? 自我是自己的终极目标 所以,你真正想要的是: def case_method case self when User do_something_with_user when SomeOtherClass do_something_else end # else is un-needed as it wi ...
  • 我个人更喜欢这样的: def self.parse(arg) key, value = arg.to_s.split(':') { 'nil' => new(nil), 'string' => new(value), 'boolean' => new(value == 'true'), 'symbol' => new(value.to_sym), 'number' => new(value.include?('.') ? BigDecimal( ...
  • 我应该如何在这个例子中实现Factory Method? 你不应该。 在基于类的编程中,工厂方法模式是一种创建模式,它使用工厂方法来处理创建对象的问题,而无需指定将要创建的对象的确切类。 如果你有专门的Name子类,那么也许吧。 我的思维过程应该如何才能使用这种设计模式? 你的第一个想法应该是“这种模式在这里是否有意义?我是否理解这种模式足以在这里尝试应用它?”。 如果答案是“是”和“是”,那么你就应用它。 更新: 你最有可能在这里使用的是工厂模式 。 在基于类的编程中,工厂是类的构造函数的抽象 class ...
  • 2.2.2 :001 > require 'set' => true 2.2.2 :002 > [1, 2, "test"].join ...
  • 你写错了你的case陈述。 它有两种形式,与其他语言相比是不寻常的。 第一种形式采用参数,并将该参数与所有可能的情况进行比较。 第二种形式没有参数,每个案例都是独立评估的。 最小的修复是这样的: def odd_or_even(string) case when string.length.even? then "even" when string.length.odd? then "odd" end end 这是因为在使用参数“Ruby”调用时,您的代码看起来像这样: def odd_o ...
  • 如果消息包含5个或更多大写单词,则以下内容将返回true。 def is_message_shouting?(message) shouted_words = 0 message.split(' ').each do |word| shouted_words += 1 if word.upcase == word end shouted_words >= 5 end puts is_message_shouting? 'THIS IS A VERY SHOUTY MESSAGE ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。