public void SetPrintAreaToTable(Excel.Worksheet oWS, string strTblName) { RAIIFuncs rFuncs = new RAIIFuncs(); using (RAIICont _raiiCont = new RAIICont()) { Excel.ListObjects oLOs = oWS.ListObjects; _raiiCont.Push(rFuncs.GetFunc(oLOs)); Excel.ListObject oLO = oLOs[strTblName]; _raiiCont.Push(rFuncs.GetFunc(oLO)); Excel.Range rngLO = oLO.Range; _raiiCont.Push(rFuncs.GetFunc(rngLO)); string prntArea = rngLO.Address; Excel.PageSetup pageSetup = oWS.PageSetup; //_raiiCont.Push(rFuncs.GetFunc(pageSetup)); pageSetup.PrintArea = prntArea; } }
public void ExportCSV(Excel.Application oAppXls, Excel.Workbooks oWBBs, Excel.Worksheet oWS, string strTableName, string strFileName) { RAIIFuncs rFuncs = new RAIIFuncs(); using (RAIICont _raiiCont = new RAIICont()) { Excel.Workbook _destWB = oWBBs.Add(); _raiiCont.Push(rFuncs.GetFunc(_destWB)); Excel.Sheets _oWSs = _destWB.Sheets; _raiiCont.Push(rFuncs.GetFunc(_oWSs)); Excel.Worksheet _destWS = _oWSs[1]; _raiiCont.Push(rFuncs.GetFunc(_destWS)); Excel.Range _rngDest = _destWS.Range["A1"]; _raiiCont.Push(rFuncs.GetFunc(_rngDest)); Excel.ListObjects _LOs = oWS.ListObjects; _raiiCont.Push(rFuncs.GetFunc(_LOs)); Excel.ListObject _srcLO = _LOs[strTableName]; _raiiCont.Push(rFuncs.GetFunc(_srcLO)); Excel.Range _srcRng = _srcLO.Range; _raiiCont.Push(rFuncs.GetFunc(_srcRng)); _srcRng.Copy(_rngDest); oAppXls.DisplayAlerts = false; _destWB.SaveAs( Filename: @"C:\Users\A.Roennburg\Documents\GH_ArbeitPlatz\Arbeits vom Sandra\MARKANT_CalculateSheet\CSV Daten\" + strFileName + ".csv" , FileFormat: Excel.XlFileFormat.xlCSV , CreateBackup: false , Local: true ); } oAppXls.DisplayAlerts = true; }
/* * Do not Parrelism here. * It will be controlled by ... Program, it just callee */ public int EntryPoint(string pathXls) { RAIIFuncs rFuncs = new RAIIFuncs(); using (RAIICont _raiiCont = new RAIICont()) { Excel.Application appExcel = new Excel.Application(); #region Removed_Code /* * Func<bool> toCall = () => * { * appExcel.Quit(); * RMarschal.ReleaseComObject(appExcel); * return true; * }; */ /* * _raiiCont.Push( new RAII<Excel.Application>( * x => { * x.Quit(); * RMarschal.ReleaseComObject(x); * return true; * } * , appExcel * ) ); */ //throw new System.Exception("OMG"); #endregion _raiiCont.Push(rFuncs.GetFunc(appExcel)); Excel.Workbooks oWBs = appExcel.Workbooks; _raiiCont.Push(rFuncs.GetFunc(oWBs)); Excel.Workbook _WB = oWBs.Open(pathXls, ReadOnly: true); _raiiCont.Push(rFuncs.GetFunc(_WB)); string strName = _WB.Name; string strBaseName = System.IO.Path.GetFileNameWithoutExtension(_WB.FullName); //System.Diagnostics.Debug.WriteLine( strBaseName ); Excel.Sheets oWSs = _WB.Sheets; _raiiCont.Push(rFuncs.GetFunc(oWSs)); Excel.Worksheet _WS = oWSs["ARBETISTABELLE"]; _raiiCont.Push(rFuncs.GetFunc(_WS)); SetPrintAreaToTable(_WS, "Tabelle1"); SetPrnAreaToSingleWidth(appExcel, _WS); _WS.ExportAsFixedFormat( Type: Excel.XlFixedFormatType.xlTypePDF , Filename: @"C:\Users\A.Roennburg\Documents\GH_ArbeitPlatz\Arbeits vom Sandra\MARKANT_CalculateSheet\PDF Daten\" + strBaseName + ".pdf" , Quality: Excel.XlFixedFormatQuality.xlQualityStandard , IncludeDocProperties: true , IgnorePrintAreas: false , OpenAfterPublish: false ); ExportCSV(appExcel, oWBs, _WS, "Tabelle1", strBaseName); } return(0); }