C# LeftHeaderPicture
时间: 2023-12-08 14:38:10 浏览: 34
C#中的LeftHeaderPicture是指在Word文档中设置左侧页眉的图片。可以使用Microsoft.Office.Interop.Word命名空间中的HeaderFooter对象来实现。以下是一个示例代码,演示如何在C#中设置左侧页眉的图片:
```csharp
using Microsoft.Office.Interop.Word;
// 创建Word文档对象
Application wordApp = new Application();
Document wordDoc = wordApp.Documents.Add();
// 获取左侧页眉
HeaderFooter leftHeader = wordDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage];
// 在左侧页眉中插入图片
leftHeader.Shapes.AddPicture(@"C:\image.jpg", ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
// 保存文档
wordDoc.SaveAs2(@"C:\test.docx");
// 关闭Word文档和应用程序
wordDoc.Close();
wordApp.Quit();
```
请注意,上述代码中的“C:\image.jpg”应替换为实际图片的路径。此外,还需要添加对Microsoft.Office.Interop.Word命名空间的引用。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)