每次调用“workbook.createFont()”都会向工作簿添加新字体。有没有方便的方法来重用这些字体?
显然,我可以在程序中重用字体对象。但是当我重新打开Java程序时,我需要一种方法来取回Font对象。
虽然可以使用“workbook.getNumberOfFonts()”和“workbook.getFontAt(i)”,但使用这些方法并不是很方便。
我的解决方法:
我在创建字体时添加一个 CustomProperty,其中保存了字体对应的编号。
Map<String, Font> fonts = new HashMap<>();
CustomProperties customProps = workbook.getProperties().getCustomProperties();
if(customProps.contains("arial_12_b")) {
short index = customProps.getProperty("arial_12_b").getI2();
fonts.put("arial_12_b", workbook.getFontAt(index));
} else {
Font font = workbook.createFont();
font.setFontName("Arial");
font.setFontHeightInPoints((short)12);
font.setBold(true);
customProps.addProperty("arial_12_b", font.getIndex());
fonts.put("arial_12_b", font);
}
Run Code Online (Sandbox Code Playgroud)
CellStyle 通过 CellUtil 类解决了同样的问题,该类检查 CellStyle 是否已存在,如果不存在则创建它。有类似 Font 的东西吗?
最好的问候
Afoee
我有一个具有内部函数的函数,对于我的单元测试,我只想测试内部函数的功能,但是当我导出该函数并调用内部函数时,npm测试返回错误。
在我的main.js:
mainFunction = () => {
functionToBeTested = () => {
// some code
}
}
module.exports = {mainFunction: mainFunction}
Run Code Online (Sandbox Code Playgroud)
在我的test.js
const chai = require("chai");
const assert = require("chai").assert;
const mainFunction = require("./main");
describe ("test", () => {
it("returns results", () => {
let result = mainfunction.functionToBeTested(args);
//equal code
});
})
Run Code Online (Sandbox Code Playgroud)
但是当我运行npm test 时,它说:
mainfunction.functionToBeTested 不是函数。
我究竟做错了什么?
定义WPF属性太长:
public static readonly DependencyProperty FooProperty =
DependencyProperty.Register("Foo", typeof(string), typeof(FooClass), new PropertyMetadata("Foooooo"));
Run Code Online (Sandbox Code Playgroud)
我有一个辅助方法,使它更短一些:
public static readonly DependencyProperty FooProperty =
WpfUtils.Property<string, FooControl>("Foo", "Foooooo");
Run Code Online (Sandbox Code Playgroud)
码:
public partial class WpfUtils
{
public static DependencyProperty Property<T, TClass>(string name)
{
return Property<T, TClass>(name, default(T));
}
public static DependencyProperty Property<T, TClass>(string name, T defaultValue)
{
return DependencyProperty.Register(name, typeof(T), typeof(TClass), new PropertyMetadata(defaultValue));
}
}
Run Code Online (Sandbox Code Playgroud)
周围有更好的帮手吗?
我想从rails time_select帮助器的输出中删除":".助手似乎在构建分钟选择框时自动输出.
有任何想法吗?
谢谢!
我试图在CakePHP应用程序中为消息板创建一个简单的Ajax表单,但我不能在我的生活中弄清楚如何正确使用Js-> submit()函数通过Ajax提交表单.
下面是我视图中的表单代码:
<?php
echo $this->Form->create('Message',array(
'type' => 'post',
'action' => 'add',
'onSubmit' => 'return false;'
));
echo $this->Form->input('name', array('label' => 'From:'));
echo $this->Form->input('text', array('label' => 'Message:'));
echo $this->Js->submit('Post Your Message', array(
'action' => 'add',
'update' => '#message_board'
));
echo $this->Form->end();
?>
<div id="message_board">
...
</div>
Run Code Online (Sandbox Code Playgroud)
这是控制器动作:
function add() {
$this->autoRender = false;
if($this->RequestHandler->isAjax()) {
$this->layout = 'ajax'; //THIS LINE NEWLY ADDED
if(!empty($this->data)) {
if($this->Message->save($this->data)) {
$this->Session->setFlash('Your Message has been posted');
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我提交表单时发生的是表单的精确副本,其包含的div在message_board div中重复.奇怪的.
显然我缺少一些东西(或几件事).如果有人有任何想法,或者知道如何使用它的良好信息来源,将非常感激.
谢谢.
更新:我尝试将新行添加 …
嘿所有,我如何在CodeIgniter的form_input()帮助函数中使用占位符标记?
谢谢 :)
我有几个变量,我希望所有控制器访问.所以我在application_controller.rb中定义了它们:
before_filter :initialize_vars
def initialize_vars
@siteTitle = "my title"
@companyName = "company"
end
Run Code Online (Sandbox Code Playgroud)
没有问题.我想用徽标做类似的事情,所以我创建了另一个用before_filter调用的方法.
def logo
image_tag("Logo.jpg", :alt => "Logo")
end
Run Code Online (Sandbox Code Playgroud)
徽标img的一个实例应链接到站点根目录,因此我调用它:
<%=h link_to logo, root_path %>
Run Code Online (Sandbox Code Playgroud)
但它在我的布局中不起作用!当我将我的logo方法添加到application_helper.rb时,一切都很完美.hhmmm.
什么/适合这些东西的适当位置?我的意思是因为我能够使它工作不正确!
我应该在application_controller中定义我的实例变量(我将其视为全局变量)和我帮助器中的logo方法,就像我已经完成的那样?我觉得我在这里缺少一些基本的理解,为什么他们需要去不同的地方.我不确定我是否正在调用"徽标"方法或者我正在使用它.我将使用我如何调用以及如何编写徽标方法,因为我觉得这两种方法都应该放在application_controller中.
想法?
谢谢!
目前,我使用以下代码将params [:id]传递给line_items创建
<%= button_to 'Add to Cart', { controller: 'line_items', action: 'create', id: brick }, class: 'green radius nice button', method: :post, remote: true %>
Run Code Online (Sandbox Code Playgroud)
但是,它会在url查询中附加id参数,我不认为button_to要做.我想要的是通过隐藏表单字段传递id param.我可以在button_to或此问题的任何解决方法中执行此操作吗?
我写了以下帮助:
def section_to_html (block)
case block[0].downcase
when "paragraph"
block.shift
block.each do |value|
return content_tag(:p, value)
end
end
end
Run Code Online (Sandbox Code Playgroud)
它目前正在解析这些数组.
["paragraph", "This is the first paragraph."]
["paragraph", "This is the second.", "And here's an extra paragraph."]
Run Code Online (Sandbox Code Playgroud)
它返回:
<p>This is the first paragraph.</p>
<p>This is the second.</p>
Run Code Online (Sandbox Code Playgroud)
有没有办法累积content_tag?所以它返回:
<p>This is the first paragraph.</p>
<p>This is the second.</p>
<p>And here's an extra paragraph.</p>
Run Code Online (Sandbox Code Playgroud)
我现在唯一的解决方案是使用部分解决方案.但是,一旦我开始添加更多案例条件,这将变得非常混乱.
我想显示电影的持续时间.现在movie.duration显示在minutes(整数)
%b Duration: #{ @movie.duration } # 134 mins
Run Code Online (Sandbox Code Playgroud)
rails是否有时间助手来表明这是一种更人性化的方式?像这样的东西:
Duration: 2h 23min
Run Code Online (Sandbox Code Playgroud) helper ×10
ruby ×2
ajax ×1
apache-poi ×1
cakephp ×1
chai ×1
codeigniter ×1
controller ×1
excel ×1
fonts ×1
forms ×1
html ×1
input ×1
java ×1
javascript ×1
methods ×1
mocha.js ×1
module ×1
post ×1
properties ×1
testing ×1
text ×1
time ×1
time-select ×1
wpf ×1