Beispiel #1
0
        private bool ExportToExcelFile(string AFilename)
        {
            bool ExportOnlyLowestLevel = false;

            // Add the parameter export_only_lowest_level to the Parameters if you don't want to export the
            // higher levels. In some reports (Supporting Churches Report or Partner Contact Report) the csv
            // output looks much nicer if it doesn't contain the unnecessary higher levels.
            if (FParameterList.Exists("csv_export_only_lowest_level"))
            {
                ExportOnlyLowestLevel = FParameterList.Get("csv_export_only_lowest_level").ToBool();
            }

            XmlDocument doc = FResultList.WriteXmlDocument(FParameterList, ExportOnlyLowestLevel);

            if (doc != null)
            {
                using (FileStream fs = new FileStream(AFilename, FileMode.Create))
                {
                    if (TCsv2Xml.Xml2ExcelStream(doc, fs, false))
                    {
                        fs.Close();
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// export to an Excel xlsx file
        /// </summary>
        public void ExportToExcelFile()
        {
            if (dlgSaveXLSXFile.FileName.Length == 0)
            {
                dlgSaveXLSXFile.FileName = this.ReportName + '.' + dlgSaveXLSXFile.DefaultExt;
            }

            if (dlgSaveXLSXFile.ShowDialog() == DialogResult.OK)
            {
                bool ExportOnlyLowestLevel = false;

                // Add the parameter export_only_lowest_level to the Parameters if you don't want to export the
                // higher levels. In some reports (Supporting Churches Report or Partner Contact Report) the csv
                // output looks much nicer if it doesn't contain the unnecessary higher levels.
                if (Parameters.Exists("csv_export_only_lowest_level"))
                {
                    ExportOnlyLowestLevel = Parameters.Get("csv_export_only_lowest_level").ToBool();
                }

                XmlDocument doc = Results.WriteXmlDocument(Parameters, ExportOnlyLowestLevel);

                if (doc != null)
                {
                    using (FileStream fs = new FileStream(dlgSaveXLSXFile.FileName, FileMode.Create))
                    {
                        if (TCsv2Xml.Xml2ExcelStream(doc, fs, false))
                        {
                            fs.Close();
                        }
                    }

                    try
                    {
                        System.Diagnostics.Process excelProcess;
                        excelProcess = new System.Diagnostics.Process();
                        excelProcess.EnableRaisingEvents = false;
                        excelProcess.StartInfo.FileName  = dlgSaveXLSXFile.FileName;
                        excelProcess.Start();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Catalog.GetString("Failed to save file"), MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }