Пример #1
0
        private void ecxelPoster()
        {
            DateTime pReadDate  = DateTime.Now;
            string   pSheetName = "Poster";

            Excel.Application oXL = null;;
            Excel._Workbook   oWB;
            Excel._Worksheet  oSheetPoster;
            Excel._Worksheet  oSheetRegnskab;
            Excel.Window      oWindow;
            Excel.Range       oRng;

            var    rec_regnskab = Program.qryAktivRegnskab();
            string SaveAs       = rec_regnskab.Eksportmappe + pSheetName + pReadDate.ToString("_yyyyMMdd_hhmmss") + ".xls";


            var JournalPoster = from h in Program.karPosteringer
                                join d1 in Program.karKontoplan on h.Konto equals d1.Kontonr into details1
                                from x in details1.DefaultIfEmpty()
                                orderby h.Nr
                                select new clsJournalposter
            {
                ds    = (x.Type == "Drift") ? "D" : "S",
                k     = IUAP(x.Type, x.DK),
                Konto = h.Konto.ToString() + "-" + x.Kontonavn,
                Dato  = h.Dato,
                Bilag = h.Bilag,
                Nr    = h.Nr,
                Id    = h.Id,
                Tekst = h.Tekst,
                Beløb = h.Bruttobeløb,
            };

            var erMedlem = from h in Program.dbData3060.tblMedlems
                           where h.Status == 1
                           select h;


            using (new ExcelUILanguageHelper())
            {
                try
                {
                    //Start Excel and get Application object.
                    oXL         = new Excel.Application();
                    oXL.Visible = true;
                    //oXL.Visible = true; //For debug

                    //Get a new workbook.

                    oWB          = oXL.Workbooks.Add((Missing.Value));
                    oSheetPoster = (Excel._Worksheet)oWB.ActiveSheet;
                    oWindow      = oXL.ActiveWindow;

                    if (pSheetName.Length > 0)
                    {
                        oSheetPoster.Name = pSheetName.Substring(0, pSheetName.Length > 34 ? 34 : pSheetName.Length);
                    }
                    int row = 1;
                    this.MainformProgressBar.Value   = 0;
                    this.MainformProgressBar.Minimum = 0;
                    this.MainformProgressBar.Maximum = (from h in Program.karPosteringer select h).Count();
                    this.MainformProgressBar.Step    = 1;
                    this.MainformProgressBar.Visible = true;
                    foreach (clsJournalposter m in JournalPoster)
                    {
                        this.MainformProgressBar.PerformStep();
                        row++;
                        Type           objectType = m.GetType();
                        PropertyInfo[] properties = objectType.GetProperties();
                        int            col        = 0;
                        foreach (PropertyInfo property in properties)
                        {
                            col++;
                            string Name = property.Name;
                            //string NamePropertyType = property.GetValue(m, null).GetType().ToString();
                            oSheetPoster.Cells[row, col] = property.GetValue(m, null);
                            if (row == 2)
                            {
                                object[] CustomAttributes = property.GetCustomAttributes(false);
                                foreach (var att in CustomAttributes)
                                {
                                    Type tp = att.GetType();
                                    if (tp.ToString() == "nsPuls3060.Fieldattr")
                                    {
                                        Fieldattr attr    = (Fieldattr)att;
                                        string    heading = attr.Heading;
                                        oSheetPoster.Cells[1, col] = heading;
                                    }
                                }
                            }
                        }
                    }

                    oRng                     = (Excel.Range)oSheetPoster.Rows[1, Missing.Value];
                    oRng.Font.Name           = "Arial";
                    oRng.Font.Size           = 12;
                    oRng.Font.Strikethrough  = false;
                    oRng.Font.Superscript    = false;
                    oRng.Font.Subscript      = false;
                    oRng.Font.OutlineFont    = false;
                    oRng.Font.Shadow         = false;
                    oRng.Font.Bold           = true;
                    oRng.HorizontalAlignment = Excel.Constants.xlCenter;
                    oRng.VerticalAlignment   = Excel.Constants.xlBottom;
                    oRng.WrapText            = false;
                    oRng.Orientation         = 0;
                    oRng.AddIndent           = false;
                    oRng.IndentLevel         = 0;
                    oRng.ShrinkToFit         = false;
                    oRng.MergeCells          = false;

                    string BottomRight = "D" + row.ToString();
                    oRng = oSheetPoster.get_Range("D2", BottomRight);
                    oRng.NumberFormat = "dd-mm-yyyy";

                    oSheetPoster.Cells.EntireColumn.AutoFit();

                    oWindow.SplitRow    = 1;
                    oWindow.FreezePanes = true;

                    oSheetPoster.get_Range("A1", Missing.Value).Select();


                    oSheetRegnskab = (Excel._Worksheet)oWB.Worksheets.Add(System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
                    oRng           = oSheetRegnskab.get_Range("C2", Missing.Value);
                    oRng.Formula   = "Antal medlemmer: " + erMedlem.Count().ToString();

                    //oXL.Visible = true; //For debug

                    PivotField _pvtField = null;
                    PivotTable _pivot    = oSheetPoster.PivotTableWizard(
                        XlPivotTableSourceType.xlDatabase,                                            //SourceType
                        oSheetPoster.get_Range(oSheetPoster.Cells[1, 1], oSheetPoster.Cells[row, 9]), //SourceData
                        oSheetRegnskab.get_Range("A3", Missing.Value),                                //TableDestination
                        "PivotTable1",                                                                //TableName
                        System.Type.Missing,                                                          //RowGrand
                        System.Type.Missing,                                                          //CollumnGrand
                        System.Type.Missing,                                                          //SaveData
                        System.Type.Missing,                                                          //HasAutoformat
                        System.Type.Missing,                                                          //AutoPage
                        System.Type.Missing,                                                          //Reserved
                        System.Type.Missing,                                                          //BackgroundQuery
                        System.Type.Missing,                                                          //OptimizeCache
                        System.Type.Missing,                                                          //PageFieldOrder
                        System.Type.Missing,                                                          //PageFieldWrapCount
                        System.Type.Missing,                                                          //ReadData
                        System.Type.Missing);                                                         //Connection

                    _pvtField             = (PivotField)_pivot.PivotFields("ds");
                    _pvtField.Orientation = XlPivotFieldOrientation.xlRowField;

                    _pvtField             = (PivotField)_pivot.PivotFields("k");
                    _pvtField.Orientation = XlPivotFieldOrientation.xlRowField;

                    _pvtField             = (PivotField)_pivot.PivotFields("Konto");
                    _pvtField.Orientation = XlPivotFieldOrientation.xlRowField;

                    _pvtField             = (PivotField)_pivot.PivotFields("Dato");
                    _pvtField.Orientation = XlPivotFieldOrientation.xlColumnField;

                    _pvtField              = (PivotField)_pivot.PivotFields("Beløb");
                    _pvtField.Orientation  = XlPivotFieldOrientation.xlDataField;
                    _pvtField.Function     = XlConsolidationFunction.xlSum;
                    _pvtField.NumberFormat = "#,##0";

                    oSheetRegnskab.Name = "Regnskab";
                    oRng = oSheetRegnskab.get_Range("D3", Missing.Value);
                    oRng.Select();
                    bool[] Periods = { false, false, false, false, true, false, false };
                    oRng.Group(true, true, Missing.Value, Periods);

                    oRng = oSheetRegnskab.get_Range("D4", "P4");
                    oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;

                    oSheetRegnskab.PageSetup.LeftHeader         = "&14Regnskab Puls 3060";
                    oSheetRegnskab.PageSetup.CenterHeader       = "";
                    oSheetRegnskab.PageSetup.RightHeader        = "&P af &N";
                    oSheetRegnskab.PageSetup.LeftFooter         = "&Z&F";
                    oSheetRegnskab.PageSetup.CenterFooter       = "";
                    oSheetRegnskab.PageSetup.RightFooter        = "&D&T";
                    oSheetRegnskab.PageSetup.LeftMargin         = oXL.InchesToPoints(0.75);
                    oSheetRegnskab.PageSetup.RightMargin        = oXL.InchesToPoints(0.75);
                    oSheetRegnskab.PageSetup.TopMargin          = oXL.InchesToPoints(1);
                    oSheetRegnskab.PageSetup.BottomMargin       = oXL.InchesToPoints(1);
                    oSheetRegnskab.PageSetup.HeaderMargin       = oXL.InchesToPoints(0.5);
                    oSheetRegnskab.PageSetup.FooterMargin       = oXL.InchesToPoints(0.5);
                    oSheetRegnskab.PageSetup.PrintHeadings      = false;
                    oSheetRegnskab.PageSetup.PrintGridlines     = true;
                    oSheetRegnskab.PageSetup.CenterHorizontally = false;
                    oSheetRegnskab.PageSetup.CenterVertically   = false;
                    oSheetRegnskab.PageSetup.Orientation        = XlPageOrientation.xlLandscape;
                    oSheetRegnskab.PageSetup.Draft           = false;
                    oSheetRegnskab.PageSetup.PaperSize       = XlPaperSize.xlPaperA4;
                    oSheetRegnskab.PageSetup.FirstPageNumber = 1;
                    oSheetRegnskab.PageSetup.Order           = XlOrder.xlDownThenOver;
                    oSheetRegnskab.PageSetup.BlackAndWhite   = false;
                    oSheetRegnskab.PageSetup.Zoom            = 100;
                    oSheetRegnskab.PageSetup.PrintErrors     = XlPrintErrors.xlPrintErrorsDisplayed;

                    oWB.ShowPivotTableFieldList = false;

                    for (var i = oWB.Worksheets.Count; i > 0; i--)
                    {
                        Excel._Worksheet oSheetWrk = (Excel._Worksheet)oWB.Worksheets.get_Item(i);
                        if ((oSheetWrk.Name != "Regnskab") && (oSheetWrk.Name != "Poster"))
                        {
                            oSheetWrk.Delete();
                        }
                    }

                    oSheetRegnskab.get_Range("A1", Missing.Value).Select();

                    oWB.SaveAs(SaveAs, Excel.XlFileFormat.xlWorkbookNormal, "", "", false, false, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    oWB.Saved   = true;
                    oXL.Visible = true;
                    this.MainformProgressBar.Visible = false;

                    this.emailExcelFile(SaveAs, "Puls3060 Regnskab");


                    //oXL.Quit();
                    //oXL = null;
                }
                catch (Exception theException)
                {
                    String errorMessage;
                    errorMessage = "Error: ";
                    errorMessage = String.Concat(errorMessage, theException.Message);
                    errorMessage = String.Concat(errorMessage, " Line: ");
                    errorMessage = String.Concat(errorMessage, theException.Source);

                    MessageBox.Show(errorMessage, "Error");
                }
            }
        }
Пример #2
0
        private void excelExternt()
        {
            DateTime pReadDate  = DateTime.Now;
            string   pSheetName = "MedlemEkstern";

            Excel.Application oXL = null;;
            Excel._Workbook   oWB;
            Excel._Worksheet  oSheet;
            Excel.Window      oWindow;
            Excel.Range       oRng;

            var    rec_regnskab = Program.qryAktivRegnskab();
            string SaveAs       = rec_regnskab.Eksportmappe + pSheetName + pReadDate.ToString("_yyyyMMdd_hhmmss") + ".xls";

            clsRest   objRest    = new clsRest();
            string    strxmldata = objRest.HttpGet2(clsRest.urlBaseType.data, "personlist");
            XDocument xmldata    = XDocument.Parse(strxmldata);
            string    Status     = xmldata.Descendants("Status").First().Value;

            if (Status != "True")
            {
                return;
            }
            var MedlemmerAll = from h in xmldata.Descendants("Person")
                               orderby clsPassXmlDoc.attr_val_int(h, "Nr")
                               select new clsMedlemExternAll
            {
                Nr        = clsPassXmlDoc.attr_val_int(h, "Nr"),
                Navn      = clsPassXmlDoc.attr_val_string(h, "Navn"),
                Kaldenavn = clsPassXmlDoc.attr_val_string(h, "Kaldenavn"),
                Adresse   = clsPassXmlDoc.attr_val_string(h, "Adresse"),
                Postnr    = clsPassXmlDoc.attr_val_string(h, "Postnr"),
                Bynavn    = clsPassXmlDoc.attr_val_string(h, "Bynavn"),
                Telefon   = clsPassXmlDoc.attr_val_string(h, "Telefon"),
                Email     = clsPassXmlDoc.attr_val_string(h, "Email"),
                Kon       = clsPassXmlDoc.attr_val_string(h, "Kon"),
                FodtDato  = clsPassXmlDoc.attr_val_date(h, "FodtDato"),
                erMedlem  = (clsPassXmlDoc.attr_val_bool(h, "erMedlem")) ? 1 : 0,
                erPBS     = (clsPassXmlDoc.attr_val_bool(h, "Tilmeldtpbs")) ? 1 : 0,
            };


            using (new ExcelUILanguageHelper())
            {
                try
                {
                    //Start Excel and get Application object.
                    oXL         = new Excel.Application();
                    oXL.Visible = true;
                    //Get a new workbook.

                    oWB     = oXL.Workbooks.Add((Missing.Value));
                    oSheet  = (Excel._Worksheet)oWB.ActiveSheet;
                    oWindow = oXL.ActiveWindow;

                    if (pSheetName.Length > 0)
                    {
                        oSheet.Name = pSheetName.Substring(0, pSheetName.Length > 34 ? 34 : pSheetName.Length);
                    }
                    int row = 1;
                    this.MainformProgressBar.Value   = 0;
                    this.MainformProgressBar.Minimum = 0;
                    this.MainformProgressBar.Maximum = (from h in Program.karMedlemmer select h).Count();
                    this.MainformProgressBar.Step    = 1;
                    this.MainformProgressBar.Visible = true;
                    foreach (clsMedlemExternAll m in MedlemmerAll)
                    {
                        this.MainformProgressBar.PerformStep();
                        row++;
                        Type           objectType = m.GetType();
                        PropertyInfo[] properties = objectType.GetProperties();
                        int            col        = 0;
                        foreach (PropertyInfo property in properties)
                        {
                            col++;
                            string Name = property.Name;
                            //string NamePropertyType = property.GetValue(m, null).GetType().ToString();
                            oSheet.Cells[row, col] = property.GetValue(m, null);
                            if (row == 2)
                            {
                                object[] CustomAttributes = property.GetCustomAttributes(false);
                                foreach (var att in CustomAttributes)
                                {
                                    Type tp = att.GetType();
                                    if (tp.ToString() == "nsPuls3060.Fieldattr")
                                    {
                                        Fieldattr attr    = (Fieldattr)att;
                                        string    heading = attr.Heading;
                                        oSheet.Cells[1, col] = heading;
                                    }
                                }
                            }
                        }
                    }
                    oRng                     = (Excel.Range)oSheet.Rows[1, Missing.Value];
                    oRng.Font.Name           = "Arial";
                    oRng.Font.Size           = 12;
                    oRng.Font.Strikethrough  = false;
                    oRng.Font.Superscript    = false;
                    oRng.Font.Subscript      = false;
                    oRng.Font.OutlineFont    = false;
                    oRng.Font.Shadow         = false;
                    oRng.Font.Bold           = true;
                    oRng.HorizontalAlignment = Excel.Constants.xlCenter;
                    oRng.VerticalAlignment   = Excel.Constants.xlBottom;
                    oRng.WrapText            = false;
                    oRng.Orientation         = 0;
                    oRng.AddIndent           = false;
                    oRng.IndentLevel         = 0;
                    oRng.ShrinkToFit         = false;
                    oRng.MergeCells          = false;

                    string BottomRight = "J" + row.ToString();
                    oRng = oSheet.get_Range("J2", BottomRight);
                    oRng.NumberFormat = "dd-mm-yyyy";

                    oSheet.Cells.EntireColumn.AutoFit();

                    oWindow.SplitRow    = 1;
                    oWindow.SplitColumn = 2;
                    oWindow.FreezePanes = true;

                    oSheet.get_Range("A1", Missing.Value).Select();

                    for (var i = oWB.Worksheets.Count; i > 0; i--)
                    {
                        Excel._Worksheet oSheetWrk = (Excel._Worksheet)oWB.Worksheets.get_Item(i);
                        if (oSheetWrk.Name != "MedlemEkstern")
                        {
                            oSheetWrk.Delete();
                        }
                    }


                    oWB.SaveAs(SaveAs, Excel.XlFileFormat.xlWorkbookNormal, "", "", false, false, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    oWB.Saved   = true;
                    oXL.Visible = true;
                    this.MainformProgressBar.Visible = false;

                    this.sendMedlem(SaveAs);

                    //oXL.Quit();
                    //oXL = null;
                }
                catch (Exception theException)
                {
                    String errorMessage;
                    errorMessage = "Error: ";
                    errorMessage = String.Concat(errorMessage, theException.Message);
                    errorMessage = String.Concat(errorMessage, " Line: ");
                    errorMessage = String.Concat(errorMessage, theException.Source);

                    MessageBox.Show(errorMessage, "Error");
                }
            }
        }
Пример #3
0
        private void excelNotPBS()
        {
            DateTime pReadDate  = DateTime.Now;
            string   pSheetName = "MedlemNotPBS";

            Excel.Application oXL = null;;
            Excel._Workbook   oWB;
            Excel._Worksheet  oSheet;
            Excel.Window      oWindow;
            Excel.Range       oRng;

            var    rec_regnskab = Program.qryAktivRegnskab();
            string SaveAs       = rec_regnskab.Eksportmappe + pSheetName + pReadDate.ToString("_yyyyMMdd_hhmmss") + ".xls";

            var MedlemmerAll = from h in Program.dbData3060.tblMedlems
                               select new clsMedlemNotPBSAll
            {
                Nr        = h.Nr,
                Navn      = h.Navn,
                Kaldenavn = h.Kaldenavn,
                Adresse   = h.Adresse,
                Postnr    = h.Postnr,
                Bynavn    = h.Bynavn,
                Telefon   = h.Telefon,
                Email     = h.Email,
                Kon       = h.Kon.ToString(),
                FodtDato  = h.FodtDato,
                erMedlem  = ((bool)Program.dbData3060.erMedlem(h.Nr)) ? 1 : 0,
                erPBS     = ((bool)Program.dbData3060.erPBS(h.Nr)) ? 1 : 0,
            };

            var MedlemmerNotPBS = from h in MedlemmerAll
                                  where h.erMedlem == 1 && h.erPBS == 0
                                  select new clsMedlemNotPBS
            {
                Nr        = h.Nr,
                Navn      = h.Navn,
                Kaldenavn = h.Kaldenavn,
                Adresse   = h.Adresse,
                Postnr    = h.Postnr,
                Bynavn    = h.Bynavn,
                Telefon   = h.Telefon,
                Email     = h.Email,
                Kon       = h.Kon,
                PBSnr     = "03985644",
                Debgrnr   = "00001",
                Kundenr   = 032001610000000 + (int)h.Nr
            };

            using (new ExcelUILanguageHelper())
            {
                try
                {
                    //Start Excel and get Application object.
                    oXL         = new Excel.Application();
                    oXL.Visible = true;
                    //Get a new workbook.

                    oWB     = oXL.Workbooks.Add((Missing.Value));
                    oSheet  = (Excel._Worksheet)oWB.ActiveSheet;
                    oWindow = oXL.ActiveWindow;

                    if (pSheetName.Length > 0)
                    {
                        oSheet.Name = pSheetName.Substring(0, pSheetName.Length > 34 ? 34 : pSheetName.Length);
                    }
                    int row = 1;
                    this.MainformProgressBar.Value   = 0;
                    this.MainformProgressBar.Minimum = 0;
                    this.MainformProgressBar.Maximum = (from h in Program.dbData3060.tblMedlems select h).Count();
                    this.MainformProgressBar.Step    = 1;
                    this.MainformProgressBar.Visible = true;
                    foreach (clsMedlemNotPBS m in MedlemmerNotPBS)
                    {
                        this.MainformProgressBar.PerformStep();
                        row++;
                        Type           objectType = m.GetType();
                        PropertyInfo[] properties = objectType.GetProperties();
                        int            col        = 0;
                        foreach (PropertyInfo property in properties)
                        {
                            col++;
                            string Name = property.Name;
                            //string NamePropertyType = property.GetValue(m, null).GetType().ToString();
                            oSheet.Cells[row, col] = property.GetValue(m, null);
                            if (row == 2)
                            {
                                object[] CustomAttributes = property.GetCustomAttributes(false);
                                foreach (var att in CustomAttributes)
                                {
                                    Type tp = att.GetType();
                                    if (tp.ToString() == "nsPuls3060.Fieldattr")
                                    {
                                        Fieldattr attr    = (Fieldattr)att;
                                        string    heading = attr.Heading;
                                        oSheet.Cells[1, col] = heading;
                                    }
                                }
                            }
                        }
                    }
                    oRng                     = (Excel.Range)oSheet.Rows[1, Missing.Value];
                    oRng.Font.Name           = "Arial";
                    oRng.Font.Size           = 12;
                    oRng.Font.Strikethrough  = false;
                    oRng.Font.Superscript    = false;
                    oRng.Font.Subscript      = false;
                    oRng.Font.OutlineFont    = false;
                    oRng.Font.Shadow         = false;
                    oRng.Font.Bold           = true;
                    oRng.HorizontalAlignment = Excel.Constants.xlCenter;
                    oRng.VerticalAlignment   = Excel.Constants.xlBottom;
                    oRng.WrapText            = false;
                    oRng.Orientation         = 0;
                    oRng.AddIndent           = false;
                    oRng.IndentLevel         = 0;
                    oRng.ShrinkToFit         = false;
                    oRng.MergeCells          = false;

                    string BottomRight = "L" + row.ToString();
                    oRng = oSheet.get_Range("L2", BottomRight);
                    oRng.NumberFormat = "##############";

                    oSheet.Cells.EntireColumn.AutoFit();

                    oWindow.SplitRow    = 1;
                    oWindow.SplitColumn = 2;
                    oWindow.FreezePanes = true;

                    oSheet.get_Range("A1", Missing.Value).Select();

                    for (var i = oWB.Worksheets.Count; i > 0; i--)
                    {
                        Excel._Worksheet oSheetWrk = (Excel._Worksheet)oWB.Worksheets.get_Item(i);
                        if (oSheetWrk.Name != "MedlemNotPBS")
                        {
                            oSheetWrk.Delete();
                        }
                    }


                    oWB.SaveAs(SaveAs, Excel.XlFileFormat.xlWorkbookNormal, "", "", false, false, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    oWB.Saved   = true;
                    oXL.Visible = true;
                    this.MainformProgressBar.Visible = false;

                    this.emailExcelFile(SaveAs, "Puls3060 Medlemmer ikke tilmeldt PBS");

                    //oXL.Quit();
                    //oXL = null;
                }
                catch (Exception theException)
                {
                    String errorMessage;
                    errorMessage = "Error: ";
                    errorMessage = String.Concat(errorMessage, theException.Message);
                    errorMessage = String.Concat(errorMessage, " Line: ");
                    errorMessage = String.Concat(errorMessage, theException.Source);

                    MessageBox.Show(errorMessage, "Error");
                }
            }
        }
Пример #4
0
        private void excelInternt()
        {
            DateTime pReadDate  = DateTime.Now;
            string   pSheetName = "MedlemIntern";

            Excel.Application oXL = null;;
            Excel._Workbook   oWB;
            Excel._Worksheet  oSheet;
            Excel.Window      oWindow;
            Excel.Range       oRng;

            var    rec_regnskab = Program.qryAktivRegnskab();
            string SaveAs       = rec_regnskab.Eksportmappe + pSheetName + pReadDate.ToString("_yyyyMMdd_hhmmss") + ".xls";

            var MedlemmerAll = from h in Program.karMedlemmer
                               join d1 in Program.dbData3060.TblMedlem on h.Nr equals d1.Nr into details1
                               from x in details1.DefaultIfEmpty()  //new TblMedlem { Nr = -1, Kon = "X", FodtDato = new DateTime(1900, 1, 1) })
                               select new clsMedlemInternAll
            {
                Nr                        = h.Nr,
                Navn                      = h.Navn,
                Kaldenavn                 = h.Kaldenavn,
                Adresse                   = h.Adresse,
                Postnr                    = h.Postnr,
                Bynavn                    = h.Bynavn,
                Telefon                   = h.Telefon,
                Email                     = h.Email,
                Kon                       = x.Kon,
                FodtDato                  = x.FodtDato,
                Bank                      = h.Bank,
                erMedlem                  = (h.erMedlem()) ? 1 : 0,
                indmeldelsesDato          = h.indmeldelsesDato,
                udmeldelsesDato           = h.udmeldelsesDato,
                kontingentBetaltTilDato   = h.kontingentBetaltTilDato,
                opkrævningsDato           = h.opkrævningsDato,
                kontingentTilbageførtDato = h.kontingentTilbageførtDato,
            };


            using (new ExcelUILanguageHelper())
            {
                try
                {
                    //Start Excel and get Application object.
                    oXL         = new Excel.Application();
                    oXL.Visible = false;
                    //Get a new workbook.

                    oWB     = oXL.Workbooks.Add((Missing.Value));
                    oSheet  = (Excel._Worksheet)oWB.ActiveSheet;
                    oWindow = oXL.ActiveWindow;

                    if (pSheetName.Length > 0)
                    {
                        oSheet.Name = pSheetName.Substring(0, pSheetName.Length > 34 ? 34 : pSheetName.Length);
                    }
                    int row = 1;
                    this.MainformProgressBar.Value   = 0;
                    this.MainformProgressBar.Minimum = 0;
                    this.MainformProgressBar.Maximum = (from h in Program.karMedlemmer select h).Count();
                    this.MainformProgressBar.Step    = 1;
                    this.MainformProgressBar.Visible = true;
                    foreach (clsMedlemInternAll m in MedlemmerAll)
                    {
                        this.MainformProgressBar.PerformStep();
                        row++;
                        Type           objectType = m.GetType();
                        PropertyInfo[] properties = objectType.GetProperties();
                        int            col        = 0;
                        foreach (PropertyInfo property in properties)
                        {
                            col++;
                            string Name = property.Name;
                            //string NamePropertyType = property.GetValue(m, null).GetType().ToString();
                            oSheet.Cells[row, col] = property.GetValue(m, null);
                            if (row == 2)
                            {
                                object[] CustomAttributes = property.GetCustomAttributes(false);
                                foreach (var att in CustomAttributes)
                                {
                                    Type tp = att.GetType();
                                    if (tp.ToString() == "nsPuls3060.Fieldattr")
                                    {
                                        Fieldattr attr    = (Fieldattr)att;
                                        string    heading = attr.Heading;
                                        oSheet.Cells[1, col] = heading;
                                    }
                                }
                            }
                        }
                    }
                    oRng                     = (Excel.Range)oSheet.Rows[1, Missing.Value];
                    oRng.Font.Name           = "Arial";
                    oRng.Font.Size           = 12;
                    oRng.Font.Strikethrough  = false;
                    oRng.Font.Superscript    = false;
                    oRng.Font.Subscript      = false;
                    oRng.Font.OutlineFont    = false;
                    oRng.Font.Shadow         = false;
                    oRng.Font.Bold           = true;
                    oRng.HorizontalAlignment = Excel.Constants.xlCenter;
                    oRng.VerticalAlignment   = Excel.Constants.xlBottom;
                    oRng.WrapText            = false;
                    oRng.Orientation         = 0;
                    oRng.AddIndent           = false;
                    oRng.IndentLevel         = 0;
                    oRng.ShrinkToFit         = false;
                    oRng.MergeCells          = false;

                    string BottomRight = "J" + row.ToString();
                    oRng = oSheet.get_Range("J2", BottomRight);
                    oRng.NumberFormat = "dd-mm-yyyy";

                    BottomRight       = "R" + row.ToString();
                    oRng              = oSheet.get_Range("M2", BottomRight);
                    oRng.NumberFormat = "dd-mm-yyyy";

                    oSheet.Cells.EntireColumn.AutoFit();

                    oWindow.SplitRow    = 1;
                    oWindow.SplitColumn = 2;
                    oWindow.FreezePanes = true;

                    oSheet.get_Range("A1", Missing.Value).Select();

                    for (var i = oWB.Worksheets.Count; i > 0; i--)
                    {
                        Excel._Worksheet oSheetWrk = (Excel._Worksheet)oWB.Worksheets.get_Item(i);
                        if (oSheetWrk.Name != "MedlemIntern")
                        {
                            oSheetWrk.Delete();
                        }
                    }


                    oWB.SaveAs(SaveAs, Excel.XlFileFormat.xlWorkbookNormal, "", "", false, false, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    oWB.Saved   = true;
                    oXL.Visible = true;
                    this.MainformProgressBar.Visible = false;


                    //oXL.Quit();
                    //oXL = null;
                }
                catch (Exception theException)
                {
                    String errorMessage;
                    errorMessage = "Error: ";
                    errorMessage = String.Concat(errorMessage, theException.Message);
                    errorMessage = String.Concat(errorMessage, " Line: ");
                    errorMessage = String.Concat(errorMessage, theException.Source);

                    MessageBox.Show(errorMessage, "Error");
                }
            }
        }