首页 \ 问答 \ 在jxl中写入Excel(Writing to Excel in jxl)

在jxl中写入Excel(Writing to Excel in jxl)

这些是进口产品

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

代码在第一行导入java.io时抛出错误但是在导入后,我得到另一个错误“use try catch”

WritableWorkbook workbook =Workbook.createWorkbook(new File("C:\\IronMan.xls"));
    WritableSheet sheet=workbook.createSheet("Tony", 0);
    Label label=new Label(0,0,"Real Name");
    sheet.addCell(label);
    Label label1=new Label(1,0,"Character Name");
    sheet.addCell(label1);
    Label label2=new Label(2,0,"Ability");
    sheet.addCell(label2);
    workbook.write();
    workbook.close();

These are the imports

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

The code is throwing error at the first line import java.io But after importing I get another error "use try catch"

WritableWorkbook workbook =Workbook.createWorkbook(new File("C:\\IronMan.xls"));
    WritableSheet sheet=workbook.createSheet("Tony", 0);
    Label label=new Label(0,0,"Real Name");
    sheet.addCell(label);
    Label label1=new Label(1,0,"Character Name");
    sheet.addCell(label1);
    Label label2=new Label(2,0,"Ability");
    sheet.addCell(label2);
    workbook.write();
    workbook.close();

原文:https://stackoverflow.com/questions/42133379
更新时间:2022-09-15 11:09

最满意答案

没有什么内置的,但是,你可以创建类似的东西来构建你自己:

public static String nl2br (String str) {
  return str.replaceAll("\n", "<br/>");
}

// Use this way:
nl2br("Hello\nworld");

// This will return "Hello<br/>world";

There's nothing built-in, however, you can create something similar that you can construct yourself:

public static String nl2br (String str) {
  return str.replaceAll("\n", "<br/>");
}

// Use this way:
nl2br("Hello\nworld");

// This will return "Hello<br/>world";

相关问答

更多
  • 看看nl2br在php.js ,这似乎正是你要找的。 基本上是: function nl2br (str, is_xhtml) { var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '
    ' : '
    '; return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'); } 编辑: 您使用nl2br( ...
  • //$content = stripslashes('content'); $content = preg_replace('~\s*
    \s*~',"
    ",$_POST['content']); $content = nl2br($content); 像这样的东西应该为你解决掉线间的多余空白。 另外,你为什么使用stripslashes? 如果你有魔术引号,这应该是必要的,你不应该有魔术引号。 无论如何,你也得到了这条线的语法错误。 编辑:仍试图解释你在说什么。 我认为这可能会有所 ...
  • 没有什么内置的,但是,你可以创建类似的东西来构建你自己: public static String nl2br (String str) { return str.replaceAll("\n", "
    "); } // Use this way: nl2br("Hello\nworld"); // This will return "Hello
    world"; There's nothing built-in, however, you can create something s ...
  • 试试这种方式: print nl2br(stripcslashes($shouts[$i]->msg)); 注意stripcslashes()函数,但不是stripslashes() 要不就: print nl2br($shouts[$i]->msg); UPD: nl2br()函数用
    替换\n 。 问题是你的文本中没有\n ,但有n或\\n 。 我认为从基础获取数据时不需要使用stripslashes() ,除非您在基础中使用了数据。 Try this way: print nl2br(st ...
  • $message_var_1 = 'test1 \r\n test2 \r\n test3'; PHP仅在" ,而不是在...内"解析\r和\n 。所以nl2br不适用于此处。 $message_var_1 = "test1 \r\n test2 \r\n test3"; $message = '
    '.nl2br($message_var_1).'
    '; 这应该有效。 $message_var_1 = 'test1 \r\n test2 \r\n t ...
  • 在nl2br_lose中: `return preg_replace("//", '', $string); //removes
    ,
    ,
    ,
    ` 当然,为了简单起见,它交换了可读性。 另一种选择是写一个函数来调用而不是nl2br: function stripnl2br($string) {return str_replace("\n", '', nl2br($string));} in nl2br_lose: `return preg_rep ...
  • 为什么不在调用nl2br之前更换多个新线路? 如果你想让他们在帖子中只使用一个新行: $firstPos = strpos($text, "\n"); if ($firstPos !== false) { $text = substr_replace(array("\r","\n"),'', $text, $firstPos + 1); } $text = nl2br($text); 如果你想让他们只使用一个连续的新行(允许foo\nbar\nbaz ): $text = preg_replace ...
  • 使用自定义nl2br()函数可以部分解决此问题(如果不是完全解决nl2br() : function nl2br_special($string){ // Step 1: Add
    tags for each line-break $string = nl2br($string); // Step 2: Remove the actual line-breaks $string = str_replace("\n", "", $string); $s ...
  • 我不确定我理解你用这个功能想要完成什么。 首先,在每个新行中插入HTML中断,然后删除除中断之外的所有标记。 首先剥离标签然后插入HTML换行符不是更明智吗? public function eliminateTags($msg) { $decodeHTML = htmlspecialchars_decode($msg); $withoutTags = strip_tags($decodeHTML); $setBreaks = nl2br($withoutTags); re ...
  • 您可以使用widget_text过滤器 function filter_text($text) { return nl2br($text); } add_filter('widget_text', 'filter_text'); You can use widget_text filter function filter_text($text) { return nl2br($text); } add_filter('widget_text', 'filter_text');

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。