本文介绍了如何使用xsl为生成的Excel文件设置页面方向和打印设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们,
以下代码适用于excel导出,但我需要明智的设置打印预览和页面作为风景套装。
任何人请帮帮我...
public static string getWorkbookTemplate()
{
StringBuilder sb = new StringBuilder(818);
sb.AppendFormat(@<?xml version =1.0?> {0},Environment.NewLine);
sb.AppendFormat(@<?mso-application progid =Excel.Sheet?> {0},Environment.NewLine);
sb.AppendFormat(@< Workbook xmlns =urn:schemas-microsoft-com:office:spreadsheet{0},Environment.NewLine);
sb.AppendFormat(@xmlns:o =urn:schemas-microsoft-com:office:office{0},Environment.NewLine);
sb.AppendFormat(@xmlns:x =urn:schemas-microsoft-com:office:excel{0},Environment.NewLine);
sb.AppendFormat(@xmlns:ss =urn:schemas-microsoft-com:office:spreadsheet{0},Environment.NewLine);
sb.AppendFormat(@xmlns:html =http://www.w3.org/TR/REC-html40> {0},Environment.NewLine);
sb.AppendFormat(@< Styles> {0},Environment.NewLine);
sb.AppendFormat(@< Style ss:ID =Defaultss:Name =Normal> {0},Environment.NewLine);
sb.AppendFormat(@< Alignment ss:Vertical =Bottom/> {0},Environment.NewLine);
sb.AppendFormat(@< Borders /> {0},Environment.NewLine);
sb.AppendFormat(@< Font ss:FontName =Times New Romanx:Family =Swissss:Size =10ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Interior /> {0},Environment.NewLine);
sb.AppendFormat(@< NumberFormat /> {0},Environment.NewLine);
sb.AppendFormat(@< Protection /> {0},Environment.NewLine);
sb.AppendFormat(@< / Style> {0},Environment.NewLine);
sb.AppendFormat(@< Style ss:ID =s62> {0},Environment.NewLine);
sb.AppendFormat(@< Alignment ss:Horizontal =Leftss:Vertical =Topss:ReadingOrder =LeftToRight/> {0},环境。新队);
sb.AppendFormat(@< Borders> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Bottomss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Leftss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Rightss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Topss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< / Borders> {0},Environment.NewLine);
sb.AppendFormat(@< Font x:CharSet =1ss:Size =10ss:Color =#000000/> {0},环境。新队);
sb.AppendFormat(@< Interior ss:Color =#D8D8D8ss:Pattern =Solid/> {0},Environment.NewLine);
sb.AppendFormat(@< page ss:PageOrientation =landscape/> {0},Environment.NewLine);
sb.AppendFormat(@< / Style> {0},Environment.NewLine);
sb.AppendFormat(@< Style ss:ID =s63> {0},Environment.NewLine);
sb.AppendFormat(@< NumberFormat ss:Format =Short Date/> {0},Environment.NewLine);
sb.AppendFormat(@< / Style> {0},Environment.NewLine);
sb.AppendFormat(@< Style ss:ID =s22> {0},Environment.NewLine);
sb.AppendFormat(@< Borders> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Bottomss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Leftss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Rightss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< Border ss:Position =Topss:LineStyle =Continuousss:Weight =1ss:Color =#000000 /> {0},Environment.NewLine);
sb.AppendFormat(@< / Borders> {0},Environment.NewLine);
sb.AppendFormat(@< page ss:PageOrientation =landscape/> {0},Environment.NewLine);
sb.AppendFormat(@< / Style> {0},Environment.NewLine);
sb.AppendFormat(@< / Styles> {0},Environment.NewLine);
sb.AppendFormat(@< WorksheetOptions> {0},Environment.NewLine);
sb.AppendFormat(@< FitToPage /> {0},Environment.NewLine);
sb.AppendFormat(@< Print x:FitWidth =1x:FitHeight =1000x:ValidPrinterInfo =/> {0},Environment.NewLine );
sb.AppendFormat(@< / WorksheetOptions> {0},Environment.NewLine);
sb.Append(@{0} \\ n< / Workbook>);
返回sb.ToString();
}
解决方案
Hi Friends,
The below code which was working good for excel export but i need sheet wise set print preview and pages as landscape set.
any one please help me on this...
public static string getWorkbookTemplate() { StringBuilder sb = new StringBuilder(818); sb.AppendFormat(@"<?xml version=""1.0""?>{0}", Environment.NewLine); sb.AppendFormat(@"<?mso-application progid=""Excel.Sheet""?>{0}", Environment.NewLine); sb.AppendFormat(@"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine); sb.AppendFormat(@" xmlns:o=""urn:schemas-microsoft-com:office:office""{0}", Environment.NewLine); sb.AppendFormat(@" xmlns:x=""urn:schemas-microsoft-com:office:excel""{0}", Environment.NewLine); sb.AppendFormat(@" xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine); sb.AppendFormat(@" xmlns:html=""http://www.w3.org/TR/REC-html40"">{0}", Environment.NewLine); sb.AppendFormat(@" <Styles>{0}", Environment.NewLine); sb.AppendFormat(@" <Style ss:ID=""Default"" ss:Name=""Normal"">{0}", Environment.NewLine); sb.AppendFormat(@" <Alignment ss:Vertical=""Bottom""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Borders/>{0}", Environment.NewLine); sb.AppendFormat(@" <Font ss:FontName=""Times New Roman"" x:Family=""Swiss"" ss:Size=""10"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Interior/>{0}", Environment.NewLine); sb.AppendFormat(@" <NumberFormat/>{0}", Environment.NewLine); sb.AppendFormat(@" <Protection/>{0}", Environment.NewLine); sb.AppendFormat(@" </Style>{0}", Environment.NewLine); sb.AppendFormat(@" <Style ss:ID=""s62"">{0}", Environment.NewLine); sb.AppendFormat(@" <Alignment ss:Horizontal=""Left"" ss:Vertical=""Top"" ss:ReadingOrder=""LeftToRight""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Borders>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" </Borders>{0}", Environment.NewLine); sb.AppendFormat(@" <Font x:CharSet=""1"" ss:Size=""10"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Interior ss:Color=""#D8D8D8"" ss:Pattern=""Solid""/>{0}", Environment.NewLine); sb.AppendFormat(@" <page ss:PageOrientation=""landscape"" />{0}", Environment.NewLine); sb.AppendFormat(@" </Style>{0}", Environment.NewLine); sb.AppendFormat(@" <Style ss:ID=""s63"">{0}", Environment.NewLine); sb.AppendFormat(@" <NumberFormat ss:Format=""Short Date""/>{0}", Environment.NewLine); sb.AppendFormat(@" </Style>{0}", Environment.NewLine); sb.AppendFormat(@" <Style ss:ID=""s22"">{0}", Environment.NewLine); sb.AppendFormat(@" <Borders>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1"" ss:Color=""#000000""/>{0}", Environment.NewLine); sb.AppendFormat(@" </Borders>{0}", Environment.NewLine); sb.AppendFormat(@" <page ss:PageOrientation=""landscape"" />{0}", Environment.NewLine); sb.AppendFormat(@" </Style>{0}", Environment.NewLine); sb.AppendFormat(@" </Styles>{0}", Environment.NewLine); sb.AppendFormat(@" <WorksheetOptions>{0}", Environment.NewLine); sb.AppendFormat(@" <FitToPage/>{0}", Environment.NewLine); sb.AppendFormat(@" <Print x:FitWidth=""1"" x:FitHeight=""1000"" x:ValidPrinterInfo=""""/>{0}", Environment.NewLine); sb.AppendFormat(@" </WorksheetOptions>{0}", Environment.NewLine); sb.Append(@"{0}\r\n</Workbook>"); return sb.ToString(); }
解决方案
这篇关于如何使用xsl为生成的Excel文件设置页面方向和打印设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!