Java 写rtf(word) excel文件

用java实现 写RTF文件 用java实现 写RTF文件 用java实现 写RTF文件 用java实现 写RTF文件 立即下载

 

二、下面就简单的解释一下这几个文件

 

1. ExcelGenerate .java文件 这个文件中每个方法都有解释,好好的看看注释

 

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 *
 * @author 岑
 *
 */
public class ExcelGenerate {

 public static HSSFWorkbook wb;
 
 private static HSSFSheet sheet;
 
 private static HSSFRow newRow;
 
 private static HSSFCellStyle cellSytle;
 
 private static HSSFCell newCell;
 
 ExcelGenerate() {
  wb = new HSSFWorkbook();
 }
 
 public HSSFWorkbook getInstance() {
  if (wb == null) {
   wb = new HSSFWorkbook();
  }
  return wb;
 }
 
 /**
  *  sheet 取得
  * @param sheet 对象 HSSFSheet
  */
 public static HSSFSheet getSheet(String sheetName) {
  sheet = wb.createSheet(sheetName);
  return sheet;
 }
 
 /**
  * 新建行
  *
  * @param sheet HSSFSheet 对象
  * @param rownum 行号 0:第一行 1:第2行...
  * @return row HSSFRow 对象
  */
 public static HSSFRow getNewRow(HSSFSheet sheet, int rownum) {
  newRow = sheet.createRow(rownum);
  return newRow;
 }
 
 public static HSSFCell getNewCell(HSSFRow row, int cellnum) {
  newCell = row.createCell(cellnum);
  return newCell;
 }
 /**
  * 合并单元格
  *
  * @param firstRow 开始行
  * @param lastRow  结束行
  * @param firstCol 开始列
  * @param lastCol  结束列
  */
 public static void CellMergedRegion(int firstRow, int lastRow, int firstCol, int lastCol) {
  CellRangeAddress region = new CellRangeAddress(firstRow, lastRow, firstCol,lastCol);
  sheet.addMergedRegion(region);
 }
 
 /**
  * 样式表
  *
  * @return CellStyle HSSFCellStyle
  */
 public static HSSFCellStyle getCellStyle() {
  // 创建单元格样式
  cellSytle = wb.createCellStyle();
  return cellSytle;
 }
 
 /**
  * 设置单元格边框
  *
  * @param colour 边框颜色 例如: HSSFColor.RED.index
  * @param borderBottom 边框底部 例如:HSSFCellStyle.BORDER_THIN
  * @param borderLeft 边框左边 例如:HSSFCellStyle.BORDER_THIN
  * @param borderRight 边框右边 例如:HSSFCellStyle.BORDER_THIN
  * @param borderTop 边框顶部 例如:HSSFCellStyle.BORDER_THIN
  * @see org.apache.poi.hssf.util.HSSFColor;
  * @see org.apache.poi.hssf.usermodel.HSSFCellStyle
  *
  */
 public static void setBorder(HSSFCellStyle sytle,short colour, short borderBottom, short borderLeft, short borderRight, short borderTop) {
  // 设置单元格边框
  sytle.setBottomBorderColor(colour);
  sytle.setBorderBottom(borderBottom);
  sytle.setBorderLeft(borderLeft);
  sytle.setBorderRight(borderRight);
  sytle.setBorderTop(borderTop);
 }
 
 /**
  * 设置单元格颜色
  *
  * @param colour 颜色设定 例如: HSSFColor.RED.index
  * @param fillPattern 填充颜色 例如:HHSSFCellStyle.SOLID_FOREGROUND
  * @see org.apache.poi.hssf.util.HSSFColor;
  * @see org.apache.poi.hssf.usermodel.HSSFCellStyle
  */
 public static void setForegroundColor(HSSFCellStyle sytle,int colour, int fillPattern) {
  // 设定单元格背景色
  sytle.setFillForegroundColor(HSSFColor.WHITE.index);
  sytle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
 }
 
 /**
  * 画表格
  *
  * @param startRow 开始行
  * @param endRow 结束行
  * @param startCell 开始格
  * @param endCell 结束格
  * @param cellSytle 表格样式
  */
 public static void setChart(int startRow, int endRow, int startCell, int endCell, HSSFCellStyle cellSytle){
  for (int i = startRow; i <= endRow; i++) {
   newRow = sheet.createRow(i);
   for (int j = startCell; j <= endCell; j++) {
    newCell = newRow.createCell(j);
    newCell.setCellStyle(cellSytle);
   }
  }
 }
 
 /**
  *
  * @param wb 工作表
  * @param filePath 文件名和路径
  * @throws IOException
  * @throws Exception
  */
 public static void saveFile(HSSFWorkbook wb, String filePath) throws IOException, Exception {
  FileOutputStream newFile = new FileOutputStream(filePath);
  wb.write(newFile);
  newFile.close();
 }
 
 /**
  * 列宽设定
  *
  * @param colNun 列号 0: 第一列....
  * @param weight 列宽 1000、2000、3000 ...
  */
 public sta

JAVA源码文本-OpenRTF:开源RTF(富文本格式)Java库:tent: JAVA原始码OpenRTF是用于RTF(富文本格式)文件的开源Java库 OpenRTF是一个Java库,用于使用LGPL和MPL开源许可证创建和编辑RTF(富文本格式)文件。 我们欢迎其他开发人员的贡献。 请随时向此GitHub存储库提交拉取请求和错误报告。 OpenRTF从OpenPDF分支出来- 使用OpenRTF作为Maven依赖项 将此添加到您的pom.xml文件以使用最新版本的OpenRTF: <dependency> <groupId>com.github.librepdf</groupId> <artifactId>openrtf</artifactId> <version>1.2.0</version> </dependency> 贡献 释放猎犬! 请发送所有请求请求。 确保可以使用LGPL和MPL双重许可来释放您的贡献。 特别是,对OpenRTF项目的拉取请求必须仅包含您自己编写的代码,或从具有完全相同的许可证的项目中复制的代码。 GPL或AGPL许可的代码将不被接受。 文献资料 编码风格 代码缩进样式为4个空格。 通常,尝试在您要修改的文件中保留编码风格。 依存 立即下载

相关推荐

java生成rtf文档,跟word文档差不多

java生成rtf文档,跟word文档差不多

跨平台的word(doc,docx,rtf)插入图片功能

跨平台支持doc,docx,rtf的图片插入,不是生成文档,而是在现有文档上追加后生成新文档。 另外需要安装OpenOffic,并且启动服务,详情见jodconverter的官网。 使用到的技术有iText,poi,jodconverter 使用方法: 1、向doc或者rtf中插入图片 InsertImageFactory iif=new InsertImageFactory(); try { InsertImage ii=iif.getInsertImage(InsertImageFactory.DocVersion); ii.doInsertAction("D:\\text.doc",new String[]{"D:\\a.jpg","D:\\b.jpg"},"D:\\textResult.doc"); } catch (NotHasThisVersionException e) { e.printStackTrace(); } catch (InvalidFilePostfixException e){ e.printStackTrace(); } 2、向docx插入图片 InsertImageFactory iif=new InsertImageFactory(); try { InsertImage ii=iif.getInsertImage(InsertImageFactory.DocxVersion); ii.doInsertAction("D:\\text.docx",new String[]{"D:\\a.jpg","D:\\b.jpg"},"D:\\textResult.docx"); } catch (NotHasThisVersionException e) { e.printStackTrace(); } catch (InvalidFilePostfixException e){ e.printStackTrace(); }

带挂牵引车倒车运动模型推导及仿真实现

半挂牵引车在倒车时,由于鞍座主销的连接限制,其运动方式与乘用车有显著差异。例如,乘用车在右侧倒车入库时,只需确定泊车起点并将方向盘向右打死。相反,牵引车在倒车时需要先向左转方向盘,当铰接角达到防折叠的临界值时,再将方向盘向右转回,以调整牵引车与挂车至直线状态,完成泊车入库。本研究旨在建立一个基于牵引车带挂车倒车运动学模型,该模型基于以下假设: 道路在车辆行驶过程中保持平坦,无凹凸不平; 车辆以低速行驶,且在运行过程中车身不发生侧倾或俯仰; 行驶过程中,轮胎无变形,无侧向滑动,且不产

jianmo的博客 2703

Field II 超声相控阵仿真系列:多角度平面波相干合成提升成像质量

本文深入探讨了Field II超声相控阵仿真中,如何通过多角度平面波相干合成技术提升成像质量。针对单次平面波成像对比度与分辨率不足的问题,详细解析了从探头建模、多角度发射延时计算到回波数据相干合成的完整流程,并提供了关键参数调优建议,以实现图像质量与计算效率的平衡。

weixin_29284885的博客 262

探针卡技术演进:从金线微针到MEMS探针的Wafer Sort革命

本文探讨了探针卡技术从传统金线微针到MEMS探针的演进,及其对晶圆测试(Wafer Sort)的革命性影响。随着芯片焊垫间距进入45微米以下,MEMS技术凭借其超高精度、超长寿命和卓越的信号完整性,成为应对高密度、高速及3D IC测试挑战的关键,显著提升了测试效率与稳定性。

lstm7chronicler的博客 369

荔枝派Lichee Nano全志F1C100s烧录避坑指南:从Fel模式到SPI Flash完整流程

本文详细介绍了荔枝派Lichee Nano基于全志F1C100s芯片的SPI Flash烧录完整流程,从FEL模式进入技巧到定制化sunxi-tools编译,再到分区策略与实战烧录步骤。针对开发者常见的烧录程序问题提供了专业解决方案,帮助用户高效完成嵌入式系统部署。

tea88的博客 793

Unified Access Control:从NAS到RRC的5G接入控制全流程解析

本文深入解析了5G统一接入控制(Unified Access Control)的全流程,从NAS到RRC的协同工作机制。通过身份核验、业务分类和动态决策三个核心步骤,UAC实现了智能调度和弹性决策,确保海量设备接入时的网络稳定性。文章详细介绍了USIM卡的身份凭证体系、NAS层的业务分类引擎以及RRC层的动态决策机制,并提供了实战案例和常见问题排查方法。

weixin_30855099的博客 595

[Dify] HTTP 请求节点总是调不通?先把请求头、参数、变量和返回 JSON 拆开查

这篇文章围绕 Dify HTTP 请求节点调不通、接口能通但流程不稳定、返回 JSON 后续节点读不到等问题展开,从 Method、URL、Header、Body、变量映射和返回字段提取几个角度梳理排查顺序。适合正在把 Dify Workflow 接入企业微信、CRM、工单系统或内部接口的读者阅读,帮助你把接口调用从一次性跑通推进到可复用、可验证的业务流程。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 3948

【C2000系列DSP的Bootloader详解】实现过程、流程图与示例代码

C2000 Bootloader 的核心逻辑可概括为 “初始化→选模式→加载程序→校验→跳转” 五步。对于小白来说,无需纠结底层寄存器配置(驱动库已封装),重点理解 “启动流程” 和 “数据传输 + 校验” 的核心思想即可。 通过本文的流程图和示例代码,相信你已经掌握了 C2000 Bootloader 的核心原理。实际开发中,可基于 TI 提供的 Bootloader 示例(C2000Ware 中自带)进行修改,快速适配自己的硬件和应用场景。

昔时扬尘处 380

【推荐100个unity插件】制作美丽 Unity 景观,增强Terrain材质表现的插件——GTS

GTS地形着色器是一款专为Unity设计的强大工具,可解决地形纹理绘制和光照处理的难题。它提供一键式配置,支持实时调整地形效果,包含细节注入、高度混合、雪注入等核心功能,并兼容网格地形和低多边形模型。插件完美集成Gaia天气系统,支持HDRP细分效果。安装后通过GTS管理器创建配置文件并应用到地形,即可快速生成高质量地形渲染。其模块化设计包含全局设置、网格转换和细节调整等面板,使开发者能灵活控制地形表现,显著提升视觉效果与性能表现。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1579

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

rejoins
博客等级 码龄22年 0粉丝 1原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值