技术标签: office
private void ExportToWps()
{
try
{
string strFileName = label14.Text + "-" + label15.Text;
string saveFileName = "";
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "doc";
saveDialog.Filter = "Word文件|*.doc";
saveDialog.FileName = strFileName;
saveDialog.ShowDialog();
saveFileName = saveDialog.FileName;
if (saveFileName.IndexOf(":") < 0) return; //被点了取消
// Word.ApplicationClass oWordApp = new Word.ApplicationClass();//建立Word 对象,启动word程序
Word.Application oWordApp = new Word.Application();
if (oWordApp == null)
{
MessageBox.Show("word版本错误!", "error");
return;
}
object missing = System.Reflection.Missing.Value;
object oTemplate = System.Windows.Forms.Application.StartupPath + "\\Normal.dot";
Word.Document oWordDoc = oWordApp.Documents.Add(ref oTemplate, ref missing, ref missing, ref missing);//新建word文档
oWordApp.Visible = false;//设置Word程序可见,如果为false 那么word不可见
//页面设置
oWordDoc.PageSetup.TopMargin = oWordApp.CentimetersToPoints(2.5f); //上
oWordDoc.PageSetup.BottomMargin = oWordApp.CentimetersToPoints(2f);//下
oWordDoc.PageSetup.LeftMargin = oWordApp.CentimetersToPoints(2.2f);//左
oWordDoc.PageSetup.RightMargin = oWordApp.CentimetersToPoints(2.2f);//右
添加页眉 林总不需要
//oWordDoc.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader; //激活页眉的编辑
//oWordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; //设置对齐方式
//string headtext1 =PcaSettings.GetSettingString (101);
//oWordApp.Selection.Font.Name = "宋体"; //设置字体
//oWordApp.Selection.Font.Size = 10.5f;
//oWordApp.Selection.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
//oWordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone; //bu添加下划线
//oWordApp.Selection.TypeText(headtext1);
//oWordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
//添加页脚
string foottext1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
oWordDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter; //激活页脚的编辑
oWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
oWordApp.Selection.Font.Name = "仿宋_GB2312";
oWordApp.Selection.Font.Size = 8;
oWordApp.Selection.TypeText(foottext1);
//添加正文
oWordDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;//激活页面内容的编辑
oWordApp.Selection.Font.Name = "黑体";//标题使用黑体
oWordApp.Selection.Font.Scaling = 100;//视图里面的比例控制
//oWordApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;
oWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
oWordApp.Selection.Font.Size = 16;
oWordApp.Selection.Font.Bold = 1;
oWordApp.Selection.TypeText(label14.Text);//主标题
oWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle;
oWordApp.Selection.TypeText(label15.Text);//副标题
oWordApp.Selection.Font.Name = "宋体";
oWordApp.Selection.TypeParagraph();//另起一段
//oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
oWordApp.Selection.Font.Size = 11;
oWordApp.Selection.Font.Bold = 0;
#region 项不加粗
//oWordApp.Selection.TypeText(layoutControlItem3.Text + label6.Text); oWordApp.Selection.TypeText(", ");
//oWordApp.Selection.TypeText(layoutControlItem4.Text + label1.Text);
//oWordApp.Selection.TypeParagraph();//另起一段
//oWordApp.Selection.TypeText(layoutControlItem5.Text + label2.Text); oWordApp.Selection.TypeText(", ");
//oWordApp.Selection.TypeText(layoutControlItem6.Text + label3.Text);
//oWordApp.Selection.TypeParagraph();//另起一段
//oWordApp.Selection.TypeText(layoutControlItem7.Text + label4.Text); oWordApp.Selection.TypeText(", ");
//oWordApp.Selection.TypeText(layoutControlItem8.Text + label5.Text);
//oWordApp.Selection.TypeParagraph();//另起一段
//oWordApp.Selection.TypeText(layoutControlItem10.Text);
oWordApp.Selection.TypeParagraph();//另起一段
//oWordApp.Selection.TypeText(label10.Text);
//SectDoc doc = GetDocument() as SectDoc;
//if (doc.FileCount > 1)
//{
// switch (doc.FileCount)
// {
// case 2:
// {
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem12.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(label17.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem15.Text + label11.Text);
// if (label12.Visible)
// {
// oWordApp.Selection.TypeText(layoutControlItem16.Text + label12.Text);
// }
// if (label13.Visible)
// {
// oWordApp.Selection.TypeText(layoutControlItem18.Text+label13.Text);
// }
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(label8.Text+";");
// oWordApp.Selection.TypeText(label9.Text);
// //oWordApp.Selection.TypeParagraph();//另起一段
// break;
// }
// case 3:
// {
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem12.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(label17.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem14.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(label19.Text);
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem15.Text + label11.Text);
// //oWordApp.Selection.TypeParagraph();//另起一段
// break;
// }
// default:
// break;
// }
//}
//else
//{
// oWordApp.Selection.TypeParagraph();//另起一段
// oWordApp.Selection.TypeText(layoutControlItem15.Text + label11.Text); oWordApp.Selection.TypeText(", ");
// oWordApp.Selection.TypeText(layoutControlItem16.Text + label12.Text); oWordApp.Selection.TypeText(", ");
// oWordApp.Selection.TypeText(layoutControlItem18.Text + label13.Text); oWordApp.Selection.TypeText(", ");
// oWordApp.Selection.TypeParagraph();//另起一段
//}
#endregion
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem3.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label6.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem4.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label1.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem5.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label2.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem6.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label3.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem7.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label4.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem8.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label5.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem10.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label10.Text);//不加粗的值
SectDoc doc = GetDocument() as SectDoc;
if (doc.FileCount > 1)
{
switch (doc.FileCount)
{
case 2:
{
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem12.Text);//加粗标题
//oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label17.Text);//不加粗的值
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem15.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label11.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
if (label12.Visible)
{
oWordApp.Selection.TypeText(layoutControlItem16.Text + label12.Text);
}
if (label13.Visible)
{
oWordApp.Selection.TypeText(layoutControlItem18.Text + label13.Text);
}
//oWordApp.Selection.TypeParagraph();//另起一段
break;
}
case 3:
{
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.TypeText(layoutControlItem12.Text);
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.TypeText(label17.Text);
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.TypeText(layoutControlItem14.Text);
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.TypeText(label19.Text);
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.TypeText(layoutControlItem15.Text + label11.Text);
//oWordApp.Selection.TypeParagraph();//另起一段
break;
}
default:
break;
}
}
else
{
oWordApp.Selection.TypeParagraph();//另起一段
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem15.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label11.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem16.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label12.Text);//不加粗的值
oWordApp.Selection.TypeText(", ");//各项之间间隔
oWordApp.Selection.Font.Bold = 1; oWordApp.Selection.TypeText(layoutControlItem18.Text);//加粗标题
oWordApp.Selection.Font.Bold = 0; oWordApp.Selection.TypeText(label13.Text);//不加粗的值
//oWordApp.Selection.TypeParagraph();//另起一段
}
oWordApp.Selection.Font.Size = 11.5f;
//表插入行
object start = oWordApp.Selection.Start;//在内容的最后插入表格
object end = oWordApp.Selection.End; ;
Word.Range tableLocation = oWordDoc.Range(ref start, ref end);
oWordDoc.Tables.Add(tableLocation, dataGridView1.RowCount + 1, dataGridView1.ColumnCount, ref missing, ref missing);
Word.Table newTable = oWordDoc.Tables[1];
//设置表格的格式
newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;//内实体边框
newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;//外实体边框
newTable.AllowAutoFit = true;
newTable.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
//写入标题
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
newTable.Cell(1, i + 1).Range.Text = dataGridView1.Columns[i].HeaderText;
}
//写入数值
for (int r = 0; r < dataGridView1.Rows.Count; r++)
{
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
//电阻计算
if (dataGridView1.Rows[r].Cells[i].Value == null)
{
newTable.Cell(r + 2, i + 1).Range.Text = "";
}
else
{
newTable.Cell(r + 2, i + 1).Range.Text = dataGridView1.Rows[r].Cells[i].Value.ToString();
}
if (i == 6)
{
newTable.Cell(r + 2, i + 1).Range.ParagraphFormat.Alignment =Word.WdParagraphAlignment.wdAlignParagraphCenter;
}
else if (i == 7)
{
}
else
{
newTable.Cell(r + 2, i + 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
}
}
System.Windows.Forms.Application.DoEvents();
}
object wdUnits;
wdUnits = Word.WdUnits.wdLine;
object nCount = dataGridView1.RowCount + 1+1;
oWordApp.Selection.MoveDown(ref wdUnits, ref nCount, ref missing);
oWordApp.Selection.Font.Size = 12;
oWordApp.Selection.Font.Bold = 1;//防腐层和综合等级项加粗显示
oWordApp.Selection.TypeText(label8.Text); oWordApp.Selection.TypeText(", ");
oWordApp.Selection.TypeText(label9.Text);
string strfilename = saveFileName;
object filename = strfilename;
//保存文档为word2000格式
oWordDoc.SaveAs2000(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
MessageBox.Show(strFileName + "导出成功", "提示", MessageBoxButtons.OK);
//以下关闭Word程序
object nochanges = Word.WdSaveOptions.wdDoNotSaveChanges;
oWordApp.Quit(ref nochanges, ref missing, ref missing);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
---------------------
作者:leader0414
来源:CSDN
原文:https://blog.csdn.net/yanpengliumin/article/details/50344799
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件
文章浏览阅读1.3k次。题目链接~~> 这题确实很经典,需要强烈的剪枝。解题思路: 一个接一个的把木棍拼起来,最后把木棍用光。* 关键的地方是几个剪枝技巧:* 设所有木棍的总长度为 Sum, 最终的答案(长度)是 L。 * 1. 首先要明白, Sum一定要能被 L 整除。_基本思路:设所有木棍的总长度为 sum, 最终的答案是 l。首先,sum一定能被 l 整除,l
文章浏览阅读6.7k次。使用SQLAlchemy四部曲:首先总结上一章的内容:使用create_engine()连接数据库Base = declarative_base() 生成orm基类,用于创建classesBase.metadata.create_all(engine) 关联engine使用metadata创建数据库表使用 session = Session(engine) 创建一个会话,便于后面对数据...
文章浏览阅读1w次,点赞4次,收藏3次。1、论文里得图片-表格--右键--选择插入题注-题注可以自定义;自己可以新建标签;2、对于文中想输入图片-表格--编号;可以用”交叉引用“设置快捷键--Alt+J;具体设置方法:(1)给[插入]-[引用]-[题注]---设置快捷键:Alt+Ttips:[工具]-[自定义]-[键盘]-[编辑]-[InsertCaption]--设置-[Alt+T]-确定;(2)给[插入]--[引用]--[交叉引用]..._word 插入交叉引用快捷键
文章浏览阅读1.6k次。注:以下以名为Test的对话框工程为例讲解对话框程序中,如果我们有拖标准控件到界面中,并且有和控件类变量绑定,则会有void CTestDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_BTN_TEST, m_testBtn); D..._ddx_control
文章浏览阅读593次。在上一篇文章 神经网络学习2【分类器+升华至神经元 搭建神经网络】中由浅入深的理解了从分类器开始如何理解神经网络的内部计算。接下来我们借用数学工具去逐步推导其计算公式,并同时建立出Python代码框架。1.神经网络公式推导1.1两层神经网络计算尝试使用只有两层、每层两个神经元的较小的神经网络,来演示神经网络如何工作:两个输入值分别为1.0和0.5,每个节点使用激活函数。使用一些随机权重:第一层仅作输入层,不需要使用激活函数。第二层中需要做一些计算,以及使用激活函数,当然,在这个简单的网络_神经网络计算流程
文章浏览阅读1.9k次。最近几年,随着短视频、小程序、直播带货的火爆,前端开发工程师越来越热门,薪资待遇也快接近后端开发工程师了,前端领域进化为内卷重灾区。然而伴随着 Vue 3.0 的发布,前端技术也迎来了一次大革新,像是字节跳动、腾讯等开始重点考察,前端程序员对 Vue 3 框架的理解和实际应用能力。不再是当年懂个生命周期、虚拟 DOM,就可以轻松进大厂的时代了。同时网上也掀起了一股学习 Vue 3 的热潮,面对着网..._手撕vue3 双向
文章浏览阅读670次。论文链接:GLMix 文章来自于LinkedIn Job Recommendation的团队。文章想说的事情其实很简单,那就是用了一个Generalized Linear Mixed Model,在Job Recommendation的Task上效果还不错。传统的评分模型,用到Linear Regression Model; 传统的投票模型,用到Logistic Regression Model_glmix
文章浏览阅读325次。我相信,每一个Java程序员都必然会遇到过这样一个异常:NullPointerException(NPE),空指针异常。这个异常让我们很痛疼,如果写的代码不够鲁棒,导致尝试访问空对象的方法或字段时就会抛出这个异常。因此合格的程序员都会在使用对象前进行判空,常见的是用if条件判断,如果对象不为空则可以继续进行访问对象字段和方法的操作,如果对象为空那么不可以进行访问对象的字段和方法的操作。常用编程范..._空判断有没有必要用optional
文章浏览阅读786次。1、我们首先要看看U盘的文件系统是哪个?打开计算机-可移动磁盘-右击属性。2、目前打多数U盘采用的都是FAT32格式,这也是大多数USB2.0船速速度比较慢的原因。我们先用文件大小测试一个它的读写速度,格子这里用的是一个大概四百兆的文件,为了让大家更直观的看到真实结果,我们以直接拷贝文件看看。3、如果你的文件系统是FAT32的话,我们就需要进行一些优化,需要将U盘磁盘格式改成NTFS格式。我们可以..._金士顿ntfs格式linux传输慢
文章浏览阅读1.5k次。欢迎来到Apache Zeppelin!本页面是有助于开始使用的说明。安装Apache Zeppelin正式支持并在以下环境下进行测试:NameValueOracle JDK1.7 (set JAVA_HOME)OSMac OSX Ubuntu 14.X _apache zeppelin 正式版本
文章浏览阅读5.1k次。1.UIImageView中的视图内容显示模式 UIImageView *imageV=[[UIImageViewalloc]init]; imageV.scaleToFill------默认缩放填充; imageV.scaleAspectfit-------有留白; imageV.AspectFill------自适应填充,视图会被裁剪;..._uiimageview image
文章浏览阅读4.6k次。Last login: Mon Feb 25 04:53:40 2019 from 10.0.0.3[root@vmhzpmysql ~]# df -hlFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 4.4G 3.5G 962M 79% /devtmpfs ..._ivextend -l 1.95t /dev/mapper/centos-rootrounding size to boundary between p