下面Demo展示了将excel内容保存成图片,
使用名字空间:
using MSExcel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Drawing;
using System.Windows.Forms;
添加API函数的声明:
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseClipboard();
[DllImport("User32.dll")]
public static extern IntPtr GetClipboardData(System.UInt32 uFormat);
/// <summary>
/// 将excel表格内容保存成JPG格式
/// </summary>
/// <param name="fileName">excel文件名</param>
/// <param name="newPicName">保存成JPG的文件名</param>
/// <returns>保存成JPG的文件名</returns>
public static string SaveToJpg(string fileName,string newPic