none
Excel和PPT转换PDF时,总是弹出正在发布的进度条窗口,请问如何屏蔽该窗口? RRS feed

  • 问题

  • Excel和PPT转换PDF时,总是弹出正在发布的进度条窗口,请问如何屏蔽该窗口?

    Excel采用Workbook.ExportAsFixedFormat进行转换

    PPT采用persentation.SaveAs进行转换

    另外还有一个问题,空的Excel和PPT文件进行转换PDF时,会弹出无法打印没有内容的文档窗口,请问如何判断Excel和PPT文件是否为空?

    两个问题,麻烦大家的解答!感激不尽!

    2014年9月17日 10:09

答案

  • 你好:

    关于进度条你可以尝试设置DisplayAlerts属性:

    excepApp.DisplayAlerts = false;
    excepApp.DisplayDocumentActionTaskPane = false;


    关于判断

    文档是否为空,Excel中可以使用Cells/UsedRange等属性来判断:

    参考这个方法:

    private bool IsWorkbookEmpty(Workbook excelBook)
            {
                try
                {
                    if (excelBook.Sheets.Count <= 0)
                    {
                        return true;
                    }
                    else
                    {
                        foreach (Worksheet sheet in excelBook.Sheets)
                        {
                            Range excelRange = sheet.UsedRange;
                            int test1 = excelRange.Columns.Count;
                            int test2 = excelRange.Rows.Count;
                            int test3 = excelRange.Count;
     
                            if (test1 > 1 || test2 > 1 || test3 > 1)
                            {
                                return false;
                            }
                            else //look for content..
                            {
                                foreach(Range cell in excelRange)
                                {
                                    if (cell.Value2 != null)
                                    {
                                        string cellValue = cell.Value2.ToString();
                                        if (cellValue.Trim().Length > 0)
                                            return false;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    return false;
                }
                return true;
            }

    对于PPT来说只需要判断一下幻灯片的数量就可以了:

    ppt.Presentations.Count;
    ppt.ActivePresentation.Slides.Count;


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年9月18日 3:01
    版主