本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.CentimetersToPoints方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.Application.CentimetersToPoints方法的具体用法?C# Microsoft.Office.Interop.Word.Application.CentimetersToPoints怎么用?C# Microsoft.Office.Interop.Word.Application.CentimetersToPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Application
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.Application.CentimetersToPoints方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReporterMSWord
public ReporterMSWord(ReportData inputData
, string templatePath, string outputFilePath, Margins margins)
{
// absolute output file path
string absOutputFilePath = string.Empty;
if (Path.IsPathRooted(outputFilePath))
absOutputFilePath = outputFilePath;
else
absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
// absolute template path
string absTemplatePath = string.Empty;
if (Path.IsPathRooted(templatePath))
absTemplatePath = templatePath;
else
absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
// does output directory exists
string outDir = Path.GetDirectoryName(absOutputFilePath);
if (!Directory.Exists(outDir))
{
try { Directory.CreateDirectory(outDir); }
catch (System.UnauthorizedAccessException /*ex*/)
{ throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
catch (Exception ex)
{ throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
}
// html file path
string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");
BuildAnalysisReport(inputData, absTemplatePath, htmlFilePath);
// opens word
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(htmlFilePath, false, true, NoEncodingDialog: true);
// embed pictures (unlinking images)
for (int i = 1; i <= wordDoc.InlineShapes.Count; ++i)
{
if (null != wordDoc.InlineShapes[i].LinkFormat && !wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument)
wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument = true;
}
// set margins (unit?)
wordDoc.PageSetup.TopMargin = wordApp.CentimetersToPoints(margins.Top);
wordDoc.PageSetup.BottomMargin = wordApp.CentimetersToPoints(margins.Bottom);
wordDoc.PageSetup.RightMargin = wordApp.CentimetersToPoints(margins.Right);
wordDoc.PageSetup.LeftMargin = wordApp.CentimetersToPoints(margins.Left);
// set print view
wordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
wordDoc.SaveAs(absOutputFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault);
_log.Info(string.Format("Saved doc report to {0}", outputFilePath));
// delete image directory
DeleteImageDirectory();
// delete html report
File.Delete(htmlFilePath);
}
示例2: Sub_Table_Click
private void Sub_Table_Click(object sender, EventArgs e)
{
object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = true;
//设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2"));
Object start = Type.Missing;
Object end = Type.Missing;
PictureBox pp = new PictureBox(); //新建一个PictureBox控件
int p1 = 0;
for (int i = 0; i < MyDS_Grid.Tables[0].Rows.Count; i++)
{
try
{
byte[] pic = (byte[])(MyDS_Grid.Tables[0].Rows[i][30]); //将数据库中的图片转换成二进制流
MemoryStream ms = new MemoryStream(pic); //将字节数组存入到二进制流中
pp.Image = Image.FromStream(ms); //二进制流Image控件中显示
pp.Image.Save(@"C:\22.bmp"); //将图片存入到指定的路径
}
catch
{
p1 = 1;
}
object rng = Type.Missing;
string strInfo = "职工基本信息表" + "(" + MyDS_Grid.Tables[0].Rows[i][1].ToString() + ")";
start = 0;
end = 0;
wordDoc.Range(ref start, ref end).InsertBefore(strInfo); //插入文本
wordDoc.Range(ref start, ref end).Font.Name = "Verdana"; //设置字体
wordDoc.Range(ref start, ref end).Font.Size = 20; //设置字体大小
wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; //设置字体局中
start = strInfo.Length;
end = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车
object missingValue = Type.Missing;
object location = strInfo.Length; //如果location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符
Microsoft.Office.Interop.Word.Range rng2 = wordDoc.Range(ref location, ref location);
Microsoft.Office.Interop.Word.Table tab = wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue);
tab.Rows.HeightRule = Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightAtLeast;
tab.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));
tab.Range.Font.Size = 10;
tab.Range.Font.Name = "宋体";
//设置表格样式
tab.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
tab.Borders.InsideLineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;
tab.Borders.InsideColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
//第5行显示
tab.Cell(1, 5).Merge(tab.Cell(5, 6));
//第6行显示
tab.Cell(6, 5).Merge(tab.Cell(6, 6));
//第9行显示
tab.Cell(9, 4).Merge(tab.Cell(9, 6));
//第12行显示
tab.Cell(12, 2).Merge(tab.Cell(12, 6));
//第13行显示
tab.Cell(13, 2).Merge(tab.Cell(13, 6));
//第14行显示
tab.Cell(14, 2).Merge(tab.Cell(14, 6));
//第1行赋值
tab.Cell(1, 1).Range.Text = "职工编号:";
tab.Cell(1, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][0].ToString();
tab.Cell(1, 3).Range.Text = "职工姓名:";
tab.Cell(1, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][1].ToString();
//插入图片
if (p1 == 0)
{
string FileName = @"C:\22.bmp";//图片所在路径
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = tab.Cell(1, 5).Range; //指定图片插入的区域
//将图片插入到单元格中
tab.Cell(1, 5).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
}
p1 = 0;
//第2行赋值
tab.Cell(2, 1).Range.Text = "民族类别:";
tab.Cell(2, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][2].ToString();
tab.Cell(2, 3).Range.Text = "出生日期:";
try
{
tab.Cell(2, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][3]).ToShortDateString());
//.........这里部分代码省略.........