Ejemplo n.º 1
0
        public override string Export()
        {
            //_panel = fi;
            string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location;
            //string excelTemplate = assemblyName.Replace("PanelSchedule.dll", "panelSchedTemplate.xlsx");
            string newFileName = m_psView.ViewName + ".xlsx";

            try
            {
                //Initialize excel
                MyApp         = new Excel.Application();
                MyApp.Visible = false;
                //MyBook = MyApp.Workbooks.Open(excelTemplate); //Template
                MyBook = MyApp.Workbooks.Add();

                MySheet = MyBook.Sheets[1] as Excel.Worksheet; //Explicit cast is not required

                //Map Cells for individual items **
                // HEADER //

                /*
                 * MySheet.Cells[1, 3] = "INSERT STRING HERE";     //PanelName
                 * MySheet.Cells[2, 3] = "ELECTRICAL ROOM";        //Location
                 * MySheet.Cells[3, 3] = "";                       //SupplyFrom
                 * MySheet.Cells[4, 3] = "Surface";                //Mounting
                 * MySheet.Cells[5, 3] = "NEMA 1";                 //Enclosure
                 */
                // CIRCUITS //

                //Implement dump to excel for testing
                DumpPanelScheduleData();

                //Resize cells
                MySheet.Columns.AutoFit();
                //Save out excel to new file
                MyBook.SaveAs(Path.Combine(PanelScheduleExport._exportDirectory, newFileName));
                MyBook.Close();

                //Working On portion (does nothing)??
                PanelScheduleData psData = m_psView.GetTableData();
                int numSlots             = psData.NumberOfSlots;            //Number of circuits
                int numCktRows           = psData.GetNumberOfCircuitRows(); //example: 42ckt = 22 numCktRows

                return(newFileName);
            }
            catch (Exception ex)
            {
                System.Exception exc = ex as System.Exception;
                if (exc.Message.Contains("0x800A03EC"))//exc.HResult == -2146827284
                {
                    throw new IOException();
                }
                else
                {
                    throw new SystemException();
                }
            }
        }
Ejemplo n.º 2
0
        public override string Export()
        {
            //_panel = fi;
            //string excelTemplate = assemblyName.Replace("PanelSchedule.dll", "panelSchedTemplate.xlsx");
            string newFileName = Path.Combine(PanelScheduleExport._exportDirectory, m_psView.ViewName + ".xlsx");

            try
            {
                //Initialize excel
                using (var wb = new ExcelPackage(new FileInfo(newFileName)))
                {
                    var ws = wb.Workbook.Worksheets.Add(m_psView.ViewName);
                    _ws = ws;
                    DumpPanelScheduleData();

                    _ws.Cells.AutoFitColumns();
                    wb.Save();
                }


                //Implement dump to excel for testing
                //DumpPanelScheduleData();

                //Resize cells
                //MySheet.Columns.AutoFit();
                //Save out excel to new file
                //MyBook.SaveAs(Path.Combine(PanelScheduleExport._exportDirectory, newFileName));
                //MyBook.Close();

                //Working On portion (does nothing)??
                PanelScheduleData psData = m_psView.GetTableData();
                int numSlots             = psData.NumberOfSlots;            //Number of circuits
                int numCktRows           = psData.GetNumberOfCircuitRows(); //example: 42ckt = 22 numCktRows

                return(newFileName);
            }
            catch (Exception ex)
            {
                System.Exception exc = ex as System.Exception;
                if (exc.Message.Contains("0x800A03EC"))//exc.HResult == -2146827284
                {
                    throw new IOException();
                }
                else
                {
                    throw new SystemException();
                }
            }
        }