コード例 #1
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            string      sourceFileName = inputFilePath;
            MsoTriState openReadonly   = MsoTriState.msoTrue;
            MsoTriState untitled       = MsoTriState.msoFalse;
            MsoTriState withWindow     = MsoTriState.msoFalse;

            PowerPoint.Presentation presentation = this._application.Presentations.Open(sourceFileName, openReadonly, untitled, withWindow);

            string targetFileName = outputFilePath;

            PowerPoint.PpSaveAsFileType saveFormat = (PowerPoint.PpSaveAsFileType)format.SaveFormat;
            MsoTriState embedTrueTypeFonts         = MsoTriState.msoTriStateMixed;

            presentation.SaveAs(targetFileName, saveFormat, embedTrueTypeFonts);

            presentation.Close();

            this._application.AutomationSecurity = originalAutomationSecurity;
        }
コード例 #2
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            string tempFilePath = Converter.GetTempFileName(".pptx");

            if (this.Options.UseAddin && Path.GetExtension(inputFilePath) == ".odp")
            {
                // convert odp to pptx
                this.ConvertWithOdfConverter(inputFilePath, tempFilePath);
                inputFilePath = tempFilePath;
            }

            string      sourceFileName = inputFilePath;
            MsoTriState openReadonly   = MsoTriState.msoTrue;
            MsoTriState untitled       = MsoTriState.msoFalse;
            MsoTriState withWindow     = MsoTriState.msoFalse;

            PowerPoint.Presentation presentation = this._application.Presentations.Open(sourceFileName, openReadonly, untitled, withWindow);

            string targetFileName = outputFilePath;

            PowerPoint.PpSaveAsFileType saveFormat = (PowerPoint.PpSaveAsFileType)format.SaveFormat;
            MsoTriState embedTrueTypeFonts         = MsoTriState.msoTriStateMixed;

            string tempFilePath2 = Converter.GetTempFileName(".pptx");

            if (this.Options.UseAddin && format.SaveFormat == (int)PowerPoint.PpSaveAsFileType.ppSaveAsOpenDocumentPresentation)
            {
                // export to odt using addin
                saveFormat = PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation;
                string tempOpenXmlDocument = tempFilePath2;
                presentation.SaveAs(tempOpenXmlDocument, saveFormat, embedTrueTypeFonts);
                presentation.Close();

                this.ConvertWithOdfConverter(tempFilePath2, outputFilePath);
            }
            else
            {
                presentation.SaveAs(targetFileName, saveFormat, embedTrueTypeFonts);
                presentation.Close();
            }

            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            if (File.Exists(tempFilePath2))
            {
                File.Delete(tempFilePath2);
            }
            this._application.AutomationSecurity = originalAutomationSecurity;
        }
コード例 #3
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            object addToRecentFiles = false;
            object encoding         = Type.Missing;

            object sourceFileName      = inputFilePath;
            object confirmConversions  = Type.Missing;
            object openReadonly        = true;
            object openPassword        = password ?? Type.Missing;
            object templatePassword    = Type.Missing;
            object revert              = Type.Missing;
            object newDocumentPassword = Type.Missing;
            object newTemplatePassword = Type.Missing;
            object openFormat          = Type.Missing;    // Word.WdOpenFormat.wdOpenFormatAuto
            object visible             = Type.Missing;
            object openAndRepair       = Type.Missing;
            object documentDirection   = Type.Missing;
            object noEncodingDialog    = Type.Missing;
            object xmlTransform        = Type.Missing;

            Word.Document document = this._application.Documents.Open(ref sourceFileName, ref confirmConversions, ref openReadonly, ref addToRecentFiles, ref openPassword, ref templatePassword, ref revert, ref newDocumentPassword, ref newTemplatePassword, ref openFormat, ref encoding, ref visible, ref openAndRepair, ref documentDirection, ref noEncodingDialog, ref xmlTransform);

            object targetFileName          = outputFilePath;
            object saveFormat              = format.SaveFormat;
            object lockComments            = Type.Missing;
            object readPassword            = password ?? Type.Missing;
            object writePassowrd           = Type.Missing;
            object readOnlyRecommended     = Type.Missing;
            object embedTrueTypeFonts      = Type.Missing;
            object saveNativePictureFormat = Type.Missing;
            object saveFormsData           = Type.Missing;
            object saveAsAOCELetter        = Type.Missing;
            object insertLineBreaks        = Type.Missing;
            object allowSubstitutions      = Type.Missing;
            object lineEnding              = Type.Missing;
            object addBiDiMarks            = Type.Missing;

            document.SaveAs(ref targetFileName, ref saveFormat, ref lockComments, ref readPassword, ref addToRecentFiles, ref writePassowrd, ref readOnlyRecommended, ref embedTrueTypeFonts, ref saveNativePictureFormat, ref saveFormsData, ref saveAsAOCELetter, ref encoding, ref insertLineBreaks, ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);

            object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            object originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat;
            object routeDocument  = true;

            ((Word._Document)document).Close(ref saveChanges, ref originalFormat, ref routeDocument);

            this._application.AutomationSecurity = originalAutomationSecurity;
        }
コード例 #4
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
            this._application.DisplayAlerts      = false;

            string tempFilePath = Converter.GetTempFileName(".xlsx");

            if (this.Options.UseAddin && Path.GetExtension(inputFilePath) == ".ods")
            {
                // convert ods to xlsx
                this.ConvertWithOdfConverter(inputFilePath, tempFilePath);
                inputFilePath = tempFilePath;
            }

            object writeResPassword = Type.Missing;
            object addToMru         = false;

            string sourceFileName            = inputFilePath;
            object updateLinks               = Type.Missing;
            object openReadOnly              = true;
            object openFormat                = Type.Missing;
            object openPassword              = password ?? Type.Missing;
            object ignoreReadOnlyRecommended = Type.Missing;
            object origin             = Type.Missing;
            object delimiter          = Type.Missing;
            object editable           = Type.Missing;
            object notify             = Type.Missing;
            object converter          = Type.Missing; // 0
            object localDataStoreSlot = Type.Missing;
            object corruptLoad        = Type.Missing;

            Excel.Workbook workbook = this._application.Workbooks.Open(sourceFileName, updateLinks, openReadOnly, openFormat,
                                                                       openPassword, writeResPassword, ignoreReadOnlyRecommended, origin, delimiter, editable,
                                                                       notify, converter, addToMru, localDataStoreSlot, corruptLoad);

            object targetFileName      = outputFilePath;
            object saveFormat          = format.SaveFormat;
            object savePassword        = password ?? Type.Missing;
            object readOnlyRecommended = Type.Missing;
            object createBackup        = Type.Missing;

            Excel.XlSaveAsAccessMode accessMode = Excel.XlSaveAsAccessMode.xlNoChange;
            object conflictResolution           = Type.Missing;
            object textCodepage     = Type.Missing;
            object textVisualLayout = Type.Missing;
            object local            = Type.Missing;
            object saveChanges      = false;
            object filename         = Type.Missing;
            object routeWorkbook    = true;

            string tempFilePath2 = Converter.GetTempFileName(".xlsx");

            if (this.Options.UseAddin && format.SaveFormat == (int)Excel.XlFileFormat.xlOpenDocumentSpreadsheet)
            {
                // export to ods using addin
                saveFormat = Excel.XlFileFormat.xlOpenXMLWorkbook;
                object tempOpenXmlDocument = tempFilePath2;
                workbook.SaveAs(tempOpenXmlDocument, saveFormat, savePassword, writeResPassword, readOnlyRecommended, createBackup, accessMode, conflictResolution, addToMru, textCodepage, textVisualLayout, local);
                workbook.Close(saveChanges, filename, routeWorkbook);

                this.ConvertWithOdfConverter(tempFilePath2, outputFilePath);
            }
            else if (format.SaveFormat != ExcelPdfFormat && format.SaveFormat != ExcelXpsFormat)
            {
                workbook.SaveAs(targetFileName, saveFormat, savePassword, writeResPassword, readOnlyRecommended, createBackup, accessMode, conflictResolution, addToMru, textCodepage, textVisualLayout, local);
                workbook.Close(saveChanges, filename, routeWorkbook);
            }
            else
            {
                Excel.XlFixedFormatType type;
                switch (format.SaveFormat)
                {
                case ExcelXpsFormat:
                    type = Excel.XlFixedFormatType.xlTypeXPS;
                    break;

                default:
                    type = Excel.XlFixedFormatType.xlTypePDF;
                    break;
                }

                object quality = Type.Missing;
                object includeDocProperties = Type.Missing;
                object ignorePrintAreas     = Type.Missing;
                object from                   = Type.Missing;
                object to                     = Type.Missing;
                object openAfterPublish       = Type.Missing;
                object fixedFormatExtClassPtr = Type.Missing;

                workbook.ExportAsFixedFormat(type, targetFileName, quality, includeDocProperties, ignorePrintAreas, from, to, openAfterPublish, fixedFormatExtClassPtr);
                workbook.Close(saveChanges, filename, routeWorkbook);
            }

            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            if (File.Exists(tempFilePath2))
            {
                File.Delete(tempFilePath2);
            }
            this._application.DisplayAlerts      = true;
            this._application.AutomationSecurity = originalAutomationSecurity;
        }
コード例 #5
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

            object writeResPassword = Type.Missing;
            object addToMru         = false;

            string sourceFileName            = inputFilePath;
            object updateLinks               = Type.Missing;
            object openReadOnly              = true;
            object openFormat                = Type.Missing;
            object openPassword              = password ?? Type.Missing;
            object ignoreReadOnlyRecommended = Type.Missing;
            object origin             = Type.Missing;
            object delimiter          = Type.Missing;
            object editable           = Type.Missing;
            object notify             = Type.Missing;
            object Converter          = Type.Missing;    // 0
            object LocalDataStoreSlot = Type.Missing;
            object corruptLoad        = Type.Missing;

            Excel.Workbook workbook = this._application.Workbooks.Open(sourceFileName, updateLinks, openReadOnly, openFormat, openPassword, writeResPassword, ignoreReadOnlyRecommended, origin, delimiter, editable, notify, Converter, addToMru, LocalDataStoreSlot, corruptLoad);

            if (format.SaveFormat != ExcelPdfFormat && format.SaveFormat != ExcelXpsFormat)
            {
                object targetFileName               = outputFilePath;
                object saveFormat                   = format.SaveFormat;
                object savePassword                 = password ?? Type.Missing;
                object readOnlyRecommended          = Type.Missing;
                object createBackup                 = Type.Missing;
                Excel.XlSaveAsAccessMode accessMode = Excel.XlSaveAsAccessMode.xlNoChange;
                object conflictResolution           = Type.Missing;
                object textCodepage                 = Type.Missing;
                object textVisualLayout             = Type.Missing;
                object local = Type.Missing;

                workbook.SaveAs(targetFileName, saveFormat, savePassword, writeResPassword, readOnlyRecommended, createBackup, accessMode, conflictResolution, addToMru, textCodepage, textVisualLayout, local);
            }
            else
            {
                Excel.XlFixedFormatType type;
                switch (format.SaveFormat)
                {
                case ExcelXpsFormat:
                    type = Excel.XlFixedFormatType.xlTypeXPS;
                    break;

                default:
                    type = Excel.XlFixedFormatType.xlTypePDF;
                    break;
                }

                object targetFileName       = outputFilePath;
                object quality              = Type.Missing;
                object includeDocProperties = Type.Missing;
                object ignorePrintAreas     = Type.Missing;
                object from                   = Type.Missing;
                object to                     = Type.Missing;
                object openAfterPublish       = Type.Missing;
                object fixedFormatExtClassPtr = Type.Missing;

                workbook.ExportAsFixedFormat(type, targetFileName, quality, includeDocProperties, ignorePrintAreas, from, to, openAfterPublish, fixedFormatExtClassPtr);
            }

            object saveChanges   = false;
            object filename      = Type.Missing;
            object routeWorkbook = true;

            workbook.Close(saveChanges, filename, routeWorkbook);

            this._application.AutomationSecurity = originalAutomationSecurity;
        }
コード例 #6
0
        public override void Convert(string inputFilePath, FormatInfo format, string outputFilePath, string password)
        {
            base.Convert(inputFilePath, format, outputFilePath, password);

            MsoAutomationSecurity originalAutomationSecurity = this._application.AutomationSecurity;

            this._application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
            this._application.DisplayAlerts      = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

            string tempFilePath = Converter.GetTempFileName(".docx");

            if (this.Options.UseAddin && Path.GetExtension(inputFilePath) == ".odt")
            {
                // convert odt to docx
                this.ConvertWithOdfConverter(inputFilePath, tempFilePath);
                inputFilePath = tempFilePath;
            }

            object addToRecentFiles = false;
            object encoding         = Type.Missing;

            object sourceFileName      = inputFilePath;
            object confirmConversions  = Type.Missing;
            object openReadonly        = true;
            object openPassword        = password ?? Type.Missing;
            object templatePassword    = Type.Missing;
            object revert              = Type.Missing;
            object newDocumentPassword = Type.Missing;
            object newTemplatePassword = Type.Missing;
            object openFormat          = Type.Missing; // Word.WdOpenFormat.wdOpenFormatAuto
            object visible             = Type.Missing;
            object openAndRepair       = Type.Missing;
            object documentDirection   = Type.Missing;
            object noEncodingDialog    = Type.Missing;
            object xmlTransform        = Type.Missing;

            Word.Document document = this._application.Documents.Open(ref sourceFileName, ref confirmConversions, ref openReadonly, ref addToRecentFiles, ref openPassword, ref templatePassword, ref revert, ref newDocumentPassword, ref newTemplatePassword, ref openFormat, ref encoding, ref visible, ref openAndRepair, ref documentDirection, ref noEncodingDialog, ref xmlTransform);

            object targetFileName          = outputFilePath;
            object saveFormat              = format.SaveFormat;
            object lockComments            = Type.Missing;
            object readPassword            = password ?? Type.Missing;
            object writePassowrd           = Type.Missing;
            object readOnlyRecommended     = Type.Missing;
            object embedTrueTypeFonts      = Type.Missing;
            object saveNativePictureFormat = Type.Missing;
            object saveFormsData           = Type.Missing;
            object saveAsAOCELetter        = Type.Missing;
            object insertLineBreaks        = Type.Missing;
            object allowSubstitutions      = Type.Missing;
            object lineEnding              = Type.Missing;
            object addBiDiMarks            = Type.Missing;
            object saveChanges             = Word.WdSaveOptions.wdDoNotSaveChanges;
            object originalFormat          = Word.WdOriginalFormat.wdOriginalDocumentFormat;
            object routeDocument           = true;


            string tempFilePath2 = Converter.GetTempFileName(".docx");

            if (this.Options.UseAddin && format.SaveFormat == (int)Word.WdSaveFormat.wdFormatOpenDocumentText)
            {
                // export to odt using addin
                saveFormat = Word.WdSaveFormat.wdFormatXMLDocument;
                object tempOpenXmlDocument = tempFilePath2;
                document.SaveAs(ref tempOpenXmlDocument, ref saveFormat, ref lockComments, ref readPassword, ref addToRecentFiles, ref writePassowrd, ref readOnlyRecommended, ref embedTrueTypeFonts, ref saveNativePictureFormat, ref saveFormsData, ref saveAsAOCELetter, ref encoding, ref insertLineBreaks, ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);
                ((Word._Document)document).Close(ref saveChanges, ref originalFormat, ref routeDocument);

                this.ConvertWithOdfConverter(tempFilePath2, outputFilePath);
            }
            else
            {
                document.SaveAs(ref targetFileName, ref saveFormat, ref lockComments, ref readPassword, ref addToRecentFiles, ref writePassowrd, ref readOnlyRecommended, ref embedTrueTypeFonts, ref saveNativePictureFormat, ref saveFormsData, ref saveAsAOCELetter, ref encoding, ref insertLineBreaks, ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);
                ((Word._Document)document).Close(ref saveChanges, ref originalFormat, ref routeDocument);
            }

            if (File.Exists(tempFilePath))
            {
                File.Delete(tempFilePath);
            }
            if (File.Exists(tempFilePath2))
            {
                File.Delete(tempFilePath2);
            }
            this._application.DisplayAlerts      = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsAll;
            this._application.AutomationSecurity = originalAutomationSecurity;
        }