当前位置:网站首页>Unity write word
Unity write word
2022-07-04 07:48:00 【Little sun works hard every day】
Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using NPOI.XWPF.UserModel;
using ICSharpCode.SharpZipLib.Zip;
using NPOI.OpenXmlFormats.Wordprocessing;
public class wordRead : MonoBehaviour
{
private void Start()
{
// Open a file , If not, create , And set access rights
XWPFDocument doc = new XWPFDocument();
FileStream file = new FileStream("D://liuyu.docx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
Debug.Log(file.CanWrite);// Check whether writing is supported
// Create paragraphs , Set paragraph alignment
XWPFParagraph p2 = doc.CreateParagraph();
XWPFParagraph p3 = doc.CreateParagraph();
p2.Alignment = ParagraphAlignment.CENTER;
// Insert a row
XWPFRun r2 = p2.CreateRun();
SetFont(r2, "000000", "shiyanbaogao", " Song style ", 16, false, true);
// Insert a photo
p3.Alignment = ParagraphAlignment.CENTER;
XWPFRun r6 = p3.CreateRun();
SetTu(r6, 200, 200, "qq");// Insert a picture
XWPFTable table = doc.CreateTable(1, 4);// establish 1*4 Table of
table.SetColumnWidth(0, 6*256);
table.SetColumnWidth(1, 10*256);
table.SetColumnWidth(2, 6*256);
table.SetColumnWidth(3, 10*256);
table.GetRow(0).GetCell(0).SetText("11111");
table.GetRow(0).GetCell(0).SetColor("00FFFF");
table.GetRow(0).GetCell(1).SetText("11111");
table.GetRow(0).GetCell(2).SetText("11111");
table.GetRow(0).GetCell(3).SetText("11111");
table.GetRow(0).GetCell(3).SetColor("00FFFF");
doc.Write(file);
file.Close();
System.Diagnostics.Process.Start("D://liuyu.docx");
}
/// <summary>
/// Operate on text
/// </summary>
/// <param name="aRun"> Paragraph object </param>
/// <param name="color"> Color </param>
/// <param name="neirong"> Written content </param>
/// <param name="ziti"> typeface </param>
/// <param name="size"> Font size </param>
/// <param name="isb"> Is it bold </param>
/// <param name="isxie"> Is it italicized </param>
public static void SetFont(XWPFRun aRun,string color,string neirong,string ziti,int size,bool isb,bool isxie)
{
aRun.IsBold = isb;
aRun.FontFamily = ziti;
aRun.FontSize = size;
aRun.SetText(neirong);
aRun.SetColor(color);
aRun.IsItalic = isxie;
}
/// <summary>
/// Load pictures and design
/// </summary>
/// <param name="r2"> Paragraph object </param>
/// <param name="sizeX">X Value </param>
/// <param name="sizeY">Y Value </param>
/// <param name="TuName"> Image name </param>
public static void SetTu(XWPFRun r2,float sizeX,float sizeY,string TuName)
{
// Insert a picture
var widthEmus = (int)(sizeX*9525);
var heightEmus = (int)(sizeY * 9525);
try
{
//using(FileStream picData=new FileStream("D://user/" + TuName + ".png", FileMode.Open, FileAccess.Read))
using (FileStream picData = new FileStream("E://UnityProgramme/word/" + TuName + ".png", FileMode.Open, FileAccess.Read))
{
r2.AddPicture(picData, (int)PictureType.PNG ,TuName+".png", widthEmus, heightEmus);
Debug.Log("png");
}
}
catch
{
try
{
// using (FileStream picData = new FileStream("D://user/" + TuName + ".jpg", FileMode.Open, FileAccess.Read))
using (FileStream picData = new FileStream("E://UnityProgramme/word/" + TuName + ".jpeg", FileMode.Open, FileAccess.Read))
{
r2.AddPicture(picData, (int)PictureType.JPEG, TuName + ".jpeg", widthEmus, heightEmus);
Debug.Log("jpeg");// Either way
}
Debug.Log("PNG Did not find JPG"+TuName);
}
catch
{
}
}
}
}
Reference resources
边栏推荐
- Flask 常用组件
- L1-028 judging prime number (10 points)
- Implementation of ZABBIX agent active mode
- How to write a summary of the work to promote the implementation of OKR?
- OKR vs. KPI 一次搞清楚这两大概念!
- 弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
- Figure guessing game
- 1. Qt入门
- OKR vs. KPI figure out these two concepts at once!
- Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
猜你喜欢
[gurobi] establishment of simple model
BUUCTF(3)
Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
Xcode 14之大变化详细介绍
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
It's healthy to drink medicinal wine like this. Are you drinking it right
This article is enough for learning advanced mysql
Practice (9-12 Lectures)
Oracle stored procedures and functions
随机推荐
Docker install MySQL
Wechat has new functions, and the test is started again
Detailed introduction to the big changes of Xcode 14
OKR vs. KPI figure out these two concepts at once!
Go h*ck yourself:online reconnaissance (online reconnaissance)
Thesis learning -- time series similarity query method based on extreme point characteristics
墨者学院-Webmin未经身份验证的远程代码执行
zabbix 5.0监控客户端
Leetcode (215) -- the kth largest element in the array
节点基础~节点操作
Xcode 14之大变化详细介绍
Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
NPM run build error
Unity-写入Word
PCIe knowledge points -010: where to get PCIe hot plug data
Zephyr 学习笔记2,Scheduling
猜数字游戏
如何用MOS管来实现电源防反接电路
Leetcode 146. LRU cache
Leetcode(215)——数组中的第K个最大元素