标签: helper

如何在 Apache POI 中重用字体?

每次调用“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

java excel fonts helper apache-poi

5
推荐指数
1
解决办法
5385
查看次数

对内部函数进行单元测试?

我有一个具有内部函数的函数,对于我的单元测试,我只想测试内部函数的功能,但是当我导出该函数并调用内部函数时,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 不是函数。

我究竟做错了什么?

javascript testing helper mocha.js chai

5
推荐指数
1
解决办法
1616
查看次数

寻找DependencyProperty.Register快捷方式

定义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)

周围有更好的帮手吗?

wpf properties helper

4
推荐指数
2
解决办法
3224
查看次数

从ruby on rails time_select helper输出中删除":"?

我想从rails time_select帮助器的输出中删除":".助手似乎在构建分钟选择框时自动输出.

有任何想法吗?

谢谢!

ruby ruby-on-rails helper time-select

4
推荐指数
1
解决办法
1344
查看次数

如何在CakePHP中使用Js-> submit()?

我试图在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中重复.奇怪的.

显然我缺少一些东西(或几件事).如果有人有任何想法,或者知道如何使用它的良好信息来源,将非常感激.

谢谢.

更新:我尝试将新行添加 …

forms ajax cakephp helper

4
推荐指数
1
解决办法
9572
查看次数

codeigniter - 输入表单占位符

嘿所有,我如何在CodeIgniter的form_input()帮助函数中使用占位符标记?

谢谢 :)

text codeigniter input helper

4
推荐指数
1
解决办法
2万
查看次数

ruby on rails在助手与控制器中的应用范围广泛的方法?

我有几个变量,我希望所有控制器访问.所以我在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中.

想法?

谢谢!

methods controller ruby-on-rails helper

4
推荐指数
1
解决办法
3093
查看次数

使用rails button_to helper生成隐藏的表单字段数据?

目前,我使用以下代码将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或此问题的任何解决方法中执行此操作吗?

post ruby-on-rails helper

4
推荐指数
2
解决办法
3064
查看次数

Rails从Helper模块返回多个content_tags

我写了以下帮助:

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)

我现在唯一的解决方案是使用部分解决方案.但是,一旦我开始添加更多案例条件,这将变得非常混乱.

html ruby module ruby-on-rails helper

4
推荐指数
2
解决办法
9481
查看次数

显示持续时间(以分钟为单位)到小时

我想显示电影的持续时间.现在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)

time ruby-on-rails helper ruby-on-rails-4

4
推荐指数
2
解决办法
2956
查看次数