社区
C#
帖子详情
十万火急!!!C#如何控制EXCEL自定义纸张的大小
jetlun
2009-01-08 03:46:50
如题!
...全文
986
6
打赏
收藏
十万火急!!!C#如何控制EXCEL自定义纸张的大小
如题!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
lunat
2009-01-08
打赏
举报
回复
LZ问题表达不准确...
jetlun
2009-01-08
打赏
举报
回复
自己搞定!!!
///使用方法 PageSetup.PaperSize = (Excel.XlPaperSize)getpname("自定义纸张名称");
protected int getpname(string pname)
{
int aaa = 9;//默认A4
System.Drawing.Printing.PrinterSettings printer = new System.Drawing.Printing.PrinterSettings();
printer.PrinterName = "要用的打印机名称";
foreach (System.Drawing.Printing.PaperSize ps in printer.PaperSizes)
{
if (ps.PaperName.Trim() == pname)
{
aaa = ps.RawKind;
}
}
return aaa;
}
on_my_way20xx
2009-01-08
打赏
举报
回复
public Hashtable getPrinterSet()
{
Word.Application privewapp = null;
Word.DocumentClass privewdoc = null;
printset = new Hashtable();
//第一次运行打印的时候弹出WORD打印对话框 并保存用户设置
object hai = 0;
privewapp = new Word.ApplicationClass();
object templateFile = Application.StartupPath + @"\data\salary.dot";
privewapp.Visible = false;
privewdoc = (Word.DocumentClass)privewapp.Documents.Add(ref templateFile, ref missing, ref missing, ref missing);
privewdoc.Activate();
Word.Dialog dlg = privewapp.Dialogs[Word.WdWordDialog.wdDialogFilePrint];
dlg.Display(ref hai);
//dlg.Execute();
// 将用户所有设置都保存起来
Object printer = vb.Interaction.CallByName(dlg, "printer", vb.CallType.Get);
Object To = vb.Interaction.CallByName(dlg, "To", vb.CallType.Get);
Object Background = vb.Interaction.CallByName(dlg, "Background", vb.CallType.Get);
Object AppendPrFile = vb.Interaction.CallByName(dlg, "AppendPrFile", vb.CallType.Get);
Object Range = vb.Interaction.CallByName(dlg, "Range", vb.CallType.Get);
Object PrToFileName = vb.Interaction.CallByName(dlg, "PrToFileName", vb.CallType.Get);
Object From = vb.Interaction.CallByName(dlg, "From", vb.CallType.Get);
Object Type = vb.Interaction.CallByName(dlg, "Type", vb.CallType.Get);
Object NumCopies = vb.Interaction.CallByName(dlg, "NumCopies", vb.CallType.Get);
Object Pages = vb.Interaction.CallByName(dlg, "Pages", vb.CallType.Get);
Object Order = vb.Interaction.CallByName(dlg, "Order", vb.CallType.Get);
Object PrintToFile = vb.Interaction.CallByName(dlg, "PrintToFile", vb.CallType.Get);
Object Collate = vb.Interaction.CallByName(dlg, "Collate", vb.CallType.Get);
Object FileName = vb.Interaction.CallByName(dlg, "FileName", vb.CallType.Get);
Object OutputPrinter = vb.Interaction.CallByName(dlg, "OutputPrinter", vb.CallType.Get);
Object DuplexPrint = vb.Interaction.CallByName(dlg, "DuplexPrint", vb.CallType.Get);
Object PrintZoomColumn = vb.Interaction.CallByName(dlg, "PrintZoomColumn", vb.CallType.Get);
Object PrintZoomRow = vb.Interaction.CallByName(dlg, "PrintZoomRow", vb.CallType.Get);
Object PrintZoomPaperHeight = vb.Interaction.CallByName(dlg, "PrintZoomPaperHeight", vb.CallType.Get);
Object ZoomPaper = vb.Interaction.CallByName(dlg, "ZoomPaper", vb.CallType.Get);
printset.Add("printer", printer);
printset.Add("To", To);
printset.Add("Background", Background);
printset.Add("AppendPrFile", AppendPrFile);
printset.Add("Range", Range);
printset.Add("PrToFileName", PrToFileName);
printset.Add("From", From);
printset.Add("Type", Type);
printset.Add("NumCopies", NumCopies);
printset.Add("Pages", Pages);
printset.Add("Order", Order);
printset.Add("PrintToFile", PrintToFile);
printset.Add("Collate", Collate);
printset.Add("FileName", FileName);
printset.Add("OutputPrinter", OutputPrinter);
printset.Add("DuplexPrint", DuplexPrint);
printset.Add("PrintZoomColumn", PrintZoomColumn);
printset.Add("PrintZoomRow", PrintZoomRow);
printset.Add("PrintZoomPaperHeight", PrintZoomPaperHeight);
printset.Add("ZoomPaper", ZoomPaper);
return printset;
}
我这个是调用WORD的打印窗口,设置打印参数并保存起来,当连续打印的时候 每次都按照这个设置来.你可以参考下,EXCEL和WORD 的调用方法很相近!
on_my_way20xx
2009-01-08
打赏
举报
回复
我之前搞过这样一个东西
C#可以调用 EXCEL里任何一个菜单的窗口,比如打印机设置窗口,同时还可以将这个窗口的配置值读取出来,
我建议你可以看看纸张设置窗口传递出的几个参数,读取他们塞到一个数组里,每次要设置的时候旧调用他
human_2
2009-01-08
打赏
举报
回复
打开你的EXCEL
新建宏,然后录制新宏,设置自定义纸张大小,然后停止录制,最后 excel 中 "工具"->"宏"->"visual basic "查看
具体代码怎么写的,然后就好办了.
j45kp
2009-01-08
打赏
举报
回复
/// 将指定范围区域拷贝到目标区域
/// </summary>
/// <param name="sheetIndex">WorkSheet索引</param>
/// <param name="startCell">要拷贝区域的开始Cell位置(比如:A10)</param>
/// <param name="endCell">要拷贝区域的结束Cell位置(比如:F20)</param>
/// <param name="targetCell">目标区域的开始Cell位置(比如:H10)</param>
public void RangeCopy(int sheetIndex,string startCell,string endCell,string targetCell)
{
if(sheetIndex > this.WorkSheetCount)
{
this.KillExcelProcess();
throw new Exception("索引超出范围,WorkSheet索引不能大于WorkSheet数量!");
}
try
{
workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(sheetIndex);
range1 = workSheet.get_Range(startCell,endCell);
range2 = workSheet.get_Range(targetCell,this.missing);
range1.Copy(range2);
}
catch(Exception e)
{
this.KillExcelProcess();
throw e;
}
}
/// <summary>
/// 将指定范围区域拷贝到目标区域
/// </summary>
/// <param name="sheetName">WorkSheet名称</param>
/// <param name="startCell">要拷贝区域的开始Cell位置(比如:A10)</param>
/// <param name="endCell">要拷贝区域的结束Cell位置(比如:F20)</param>
/// <param name="targetCell">目标区域的开始Cell位置(比如:H10)</param>
public void RangeCopy(string sheetName,string startCell,string endCell,string targetCell)
{
try
{
Excel.Worksheet sheet = null;
for(int i=1;i<=this.WorkSheetCount;i++)
{
workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(i);
if(workSheet.Name == sheetName)
{
sheet = workSheet;
}
}
if(sheet != null)
{
for(int i=sheetCount;i>=1;i--)
{
range1 = sheet.get_Range(startCell,endCell);
range2 = sheet.get_Range(targetCell,this.missing);
range1.Copy(range2);
}
}
else
{
this.KillExcelProcess();
throw new Exception("名称为\"" + sheetName + "\"的工作表不存在");
}
}
catch(Exception e)
{
this.KillExcelProcess();
throw e;
}
}
非常感谢您留心我这份系统诊断报告,小菜鸟
十万火急
等待您的帮助!
经典 非常感谢您留心我这份系统诊断报告,小菜鸟
十万火急
等待您的帮助! 该诊断报告由360安全卫士提供 http://www.360safe.com 诊断时间: 2008-12-10 13:44:18
小学成语大赛模板PPT学习教案.pptx
小学成语大赛模板PPT学习教案.pptx
《读笑话学成语1》31-40.ppt
《读笑话学成语1》31-40.ppt
精品(2021-2022年)资料语文S版小学五年级语文下册期末试卷及答案.doc
精品课件
怀山襄陵谓洪水汹涌奔腾溢上山陵.doc
怀山襄陵谓洪水汹涌奔腾溢上山陵.doc
C#
111,130
社区成员
642,542
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章