C# 操作word 插入直线,求代码

qinjingfeng 2009-09-22 11:14:32
用C#操作word,现在要在红头下插入一条直线
求代码!
...全文
444 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LutzMark 2009-09-22
  • 打赏
  • 举报
回复
    public Image CreateImage(int width,int height,int x,int y,int length,Color color)
{
//画图初始化
Image bMap = new Bitmap(width, height);
Graphics gph = Graphics.FromImage(bMap);
Brush brush = new SolidBrush(color);
setBrush(ref brush);

try
{
PointF cPt = new PointF(x, y);
gph.DrawLine(Pens.Blue, cPt.X, cPt.Y, cPt.X + length, cPt.Y);
}
catch (Exception ex)
{
}
return bMap;
}
LutzMark 2009-09-22
  • 打赏
  • 举报
回复
Griphics类画点输出Image,调用api输出word

Image输出到word的代码
    public static void ImageToWord(Image image)
{
string fileName = "tmp.jpg";
image.Save(fileName);
FileInfo fi = new FileInfo(fileName);
try
{

Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application oword = new Microsoft.Office.Interop.Word.Application();

Document doc = oword.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
oword.Selection.Font.Bold = 1;
oword.Selection.Font.Size = 12;
oword.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;

oword.Visible = true;

object LinkToFile = false;

oword.Application.Selection.InlineShapes.AddPicture(fi.FullName, ref Nothing, ref Nothing, ref Nothing); //doc为活动文档的名称,即正在操作的文档
}
catch (Exception ex) { Log.WriteErLog(ex.Message); }
finally
{
System.Diagnostics.Process[] CurrentProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
for (int i = 0; i < CurrentProcess.Length; i++)
{
if (CurrentProcess[i].MainWindowHandle.ToInt32() == 0)
{
try
{
CurrentProcess[i].Kill();
}
catch
{
}
}
}
}

}
qinjingfeng 2009-09-22
  • 打赏
  • 举报
回复
顶起
hyblusea 2009-09-22
  • 打赏
  • 举报
回复
VBA 代码

ActiveDocument.Shapes.AddLine(144#, 255.3, 459#, 255.3).Select
qinjingfeng 2009-09-22
  • 打赏
  • 举报
回复
在顶
qinjingfeng 2009-09-22
  • 打赏
  • 举报
回复
多谢上面的大仙,
是不是复杂了点,我一直在查word.Selection下的方法,就差个类似insertLine这样的东西,脑热!!

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧