2024年4月11日发(作者:)
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
using ;
using ;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CreateWordFile("c:");
}
public string CreateWordFile(string CheckedInfo)
{
string message = "";
try
{
Object Nothing = ;
Directory("C:/CNSI"); //创建文件所在目录
string name = "CNSI_" + DateString()+".doc";
object filename = "C://CNSI//" + name; //文件保存路径
//创建Word文档
ation WordApp = new
ationClass();
nt WordDoc = (ref Nothing, ref Nothing,
ref Nothing, ref Nothing);
//添加页眉
= ineView;
ew = PrimaryHeader;
After("[页眉内容]");
ent =
nParagraphRight;//设置右对齐
ew = MainDocument;//跳出页眉设置
acing = 15f;//设置文档的行间距
//移动焦点并换行
object count = 14;
object WdLine = ;//换一行;
wn(ref WdLine, ref count, ref Nothing);//移动焦点
ragraph();//插入段落
//文档中创建表格
newTable = (, 12, 3,
ref Nothing, ref Nothing);
//设置表格样式
eLineStyle =
StyleThickThinLargeGap;
LineStyle = StyleSingle;
s[1].Width = 100f;
s[2].Width = 220f;
s[3].Width = 105f;
//填充表格内容
(1, 1). = "产品详细信息表";
(1, 1). = 2;//设置单元格中字体为粗体
//合并单元格
(1, 1).Merge((1, 3));
//填充表格内容
(2, 1). = "产品基本信息";
(2, 1). = rDarkBlue;//设
置单元格内字体颜色
//合并单元格
(2, 1).Merge((2, 3));
//填充表格内容
(3, 1). = "品牌名称:";
(3, 2). = "BrandName";
//纵向合并单元格
(3, 3).Select();//选中一行
alAlignment =
AlignVerticalCenter;
alAlignment
ent
=
=
AlignVerticalCenter;//垂直居中
nParagraphCenter;//水平居中
object moveUnit = ;
object moveCount = 5;
object moveExtend = nd;
wn(ref moveUnit, ref moveCount, ref moveExtend);
();
//插入图片
string FileName = @"c:";//图片所在路径
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = ;
ture(FileName, ref LinkToFile, ref
SaveWithDocument, ref Anchor);
Shapes[1].Width = 100f;//图片宽度
Shapes[1].Height = 100f;//图片高度
//将图片设置为四周环绕型
s =
Shapes[1].ConvertToShape();
= Square;
(12, 1). = "产品特殊属性";
(12, 1).Merge((12, 3));
//在表格中增加行
[1].(ref Nothing);
= "文档创建时间:" + ng();//“落款”
//文件保存
(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref
Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref
Nothing, ref Nothing);
(ref Nothing, ref Nothing, ref Nothing);
(ref Nothing, ref Nothing, ref Nothing);
message=name+"文档生成成功,以保存到C:CNSI下";
}
catch
{
message = "文件导出异常!";
}
return message;
}
}
}
ent =
nParagraphRight;
关于上面的代码,我想把生成的word文件是横向,现在默认是竖的.还有想把newTable表的边框去掉,
应该怎么设置?


发布评论