当前位置:网站首页>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
边栏推荐
- Text processing function sorting in mysql, quick search of collection
- The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
- Comparison between applet framework and platform compilation
- 21个战略性目标实例,推动你的公司快速发展
- Zephyr learning notes 1, threads
- BibTex中参考文献种类
- Introduction to neural network (Part 2)
- 2022-021ARTS:下半年開始
- rapidjson读写json文件
- 墨者学院-Webmin未经身份验证的远程代码执行
猜你喜欢
Zephyr 学习笔记2,Scheduling
深入浅出:了解时序数据库 InfluxDB
Zephyr study notes 2, scheduling
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
论文学习——基于极值点特征的时间序列相似性查询方法
【性能測試】一文讀懂Jmeter
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
Text processing function sorting in mysql, quick search of collection
BUUCTF(3)
随机推荐
Wechat has new functions, and the test is started again
Leetcode 23. Merge K ascending linked lists
[Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
BibTex中参考文献种类
Using the rate package for data mining
Leetcode(215)——数组中的第K个最大元素
[go basics] 1 - go go
猜数字游戏
【性能測試】一文讀懂Jmeter
Blog stop statement
NPM run build error
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Life planning (flag)
Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
大学阶段总结
促进OKR落地的工作总结该如何写?
Système de surveillance zabbix contenu de surveillance personnalisé
L1-021 important words three times (5 points)