Aspose.Cells转换excel为pdf时,表格撕裂为第二页问题

Posted 棉晗榜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Aspose.Cells转换excel为pdf时,表格撕裂为第二页问题相关的知识,希望对你有一定的参考价值。

/// <summary>
/// 将excel转换为PDF
/// </summary>
/// <param name="excelFile">".xls", ".xlsx"类型的文件路径</param>
/// <param name="pdfFilePath">生成的PDF文件</param>
/// <returns></returns>
public static async Task<(bool, string)> ExcelToPdf(string excelFile, string pdfSavePath)

	bool isPass = false;
	//string pdfSavePath = string.Empty;
	string msg = string.Empty;
	await Task.Run(() =>
	
		try
		
			//excel转换为pdf
			Workbook document = new Workbook(excelFile);

			Aspose.Cells.Style style = document.Styles[document.Styles.Add()];
			style.ShrinkToFit = true;

			int cnt = document.Worksheets.Count;
			for (int i = 0; i < cnt; i++)
			
				Aspose.Cells.Worksheet sheet = document.Worksheets[i];
				sheet.IsPageBreakPreview = true;

				//sheet.AutoFitColumns();
				//sheet.AutoFitRows();

				sheet.PageSetup.FooterMargin = 0;
				sheet.PageSetup.HeaderMargin = 0;

				//2019-10-12 17:55:55   修改,解决excel文件预览表格时撕裂到第二页了
				sheet.PageSetup.RightMargin = 0;
				sheet.PageSetup.LeftMargin = 0;
				sheet.PageSetup.CenterHorizontally = true;
			

			//string time = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
			//pdfSavePath = "d:\\\\" + time + ".pdf";
			document.Save(pdfSavePath, Aspose.Cells.SaveFormat.Pdf);
			isPass = true;
		
		catch (Exception ex)
		
			pdfSavePath = string.Empty;
			isPass = false;
			msg = ex.Message;
			LogHelpter.AddLog(ex.ToString());
		
	);
	return (isPass, msg);

 

以上是关于Aspose.Cells转换excel为pdf时,表格撕裂为第二页问题的主要内容,如果未能解决你的问题,请参考以下文章

Aspose Cells Excel模板转PDF Linux中文乱码解决

Aspose.Cells的介绍

使用Aspose.Cells导出Excel遇到的日期格式问题

使用Aspose.Cells如何获取Excel中的真实数据?

aspose.cells导出excel怎么显示为数字格式

C# Aspose.Cells 将数据设置为具有格式的 Excel 文件