c# 自动选择打印机 打印Word文档

来源:百度知道 编辑:UC知道 时间:2024/05/28 16:45:33
根据Word文档名中的城市名,如“苏州001.doc”自动选择苏州的打印机,打印该Word,word中会有表格,每天城市的打印机都已安装。

你是指用c#编程?还是问的普通的办公问题?
普通办公问题:麻烦你打开“苏州001.doc”,文件->打印->选择好相应城市的打印机->打印
编程问题:
获取文件名中的城市名你会吧,
然后根据城市名得到打印机名(这一步只能你手动设定,比如苏州(城市名)对应打印机名是001,你也可以把对应的打印机名设为城市名 这样就ok了)
然后运用打印类:
public class RawPrinterHelper
{
// [Methods]
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, SetLastError = true, ExactSpelling = true)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, SetLastError = true, ExactSpelling = true)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, SetLastError = true, ExactSpelling = true)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv&quo