cancel
Showing results for 
Search instead for 
Did you mean: 

Exportar para Excel tem comportamento diferente entre o SDK .Net e Biblioteca para Delphi

alair
Explorer
0 Kudos
460

Necessito exportar a visualização do RPT para excel para uso com um RPA onde são descartadas as colunas vazias do documento, e as colunas que ficam tem o tamanho correto dos campos do relatório.

Na versão utilizando o Delphi, consigo realizar essa tarefa de forma correta, porém, tenho problemas em relatórios com mais de 200Kb e a orientação da SAP foi utilizar o SDK .Net, pois, não existem mais drivers para Delphi.

Infelizmente a exportação utilizando o SDK .Net não tem o mesmo comportamento, pois, não apresenta a tela de Opções para a exportação para Excel, além do fato do formato XLS gerado apresentar mais colunas que as colunas de "Detlhes" do RPT.

Existe na "Community Resources" (https://answers.sap.com/questions/11732379/how-to-bring-the-excel-format-options-dialog-box.html) usa solicitação para customização das opções de exportação para o Excel, mas os dois links disponíveis na resposta não foram convertidos para a nova experiência da Comunidade SAP:(https://archive.sap.com/content-not-migrated)

View Entire Topic
0 Kudos

rest of code:

            if (ExportTypeSelected == "crReportExportFormatPageToXLSX") // new in SP30
            #region MSPageXLSX
            {
                // This works do not alter
                // this gets the report name and sets the export name to be the same less the extension
                string outputFileName = "";
                string MyRptName = rpt.FileName.ToString();
                outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
                outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "xlsx";

                try // test if the reprot is saved in CR 2020
                {
                    if ((rpt.HistoryInfos[0].BuildVersion.ToString()) != null)
                    {
                        if ((rpt.HistoryInfos[0].BuildVersion.ToString()).Substring(0, 4) != "14.3")
                        {
                            MessageBox.Show("Report must be saved in CR 2020 to support this feature");
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Report must be saved in CR 2020 to support this feature");
                    return;
                }

                try
                {
                    if (File.Exists(outputFileName))
                    {
                        File.Delete(outputFileName);
                    }

                    CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions RASXLXSExportOpts = (ExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPageToXLSX);
                    if (RASXLXSExportOpts != null)
                    {
                        btnReportObjects.Text  = "Excel - BaseAreaGroupNumber:       " + RASXLXSExportOpts.BaseAreaGroupNumber.ToString() + "\n";
                        btnReportObjects.Text += "Excel - BaseAreaType:              " + RASXLXSExportOpts.BaseAreaType.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ConstantColWidth:          " + RASXLXSExportOpts.ConstantColWidth.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ConvertDatesToStrings:     " + RASXLXSExportOpts.ConvertDatesToStrings.ToString() + "\n";
                        btnReportObjects.Text += "Excel - CurrentPageNumber:         " + RASXLXSExportOpts.CurrentPageNumber.ToString() + "\n";
                        btnReportObjects.Text += "Excel - EndPageNumber:             " + RASXLXSExportOpts.EndPageNumber.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ExcelTabHasColumnHeadings: " + RASXLXSExportOpts.ExcelTabHasColumnHeadings.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ExportPageAreaPairType:    " + RASXLXSExportOpts.ExportPageAreaPairType.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ExportPageBreaks:          " + RASXLXSExportOpts.ExportPageBreaks.ToString() + "\n";
                        btnReportObjects.Text += "Excel - MaintainRelativeObjectPos: " + RASXLXSExportOpts.MaintainRelativeObjectPosition.ToString() + "\n";
                        btnReportObjects.Text += "Excel - ShowGridlines:             " + RASXLXSExportOpts.ShowGridlines.ToString() + "\n";
                        btnReportObjects.Text += "Excel - StartPageNumber:           " + RASXLXSExportOpts.StartPageNumber.ToString() + "\n";
                        btnReportObjects.Text += "Excel - UseConstantColWidth:       " + RASXLXSExportOpts.UseConstantColWidth.ToString() + "\n";
                    }

                    // Manually set the values
                    //RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
                    //RasXLSExpOpts.UseConstantColWidth = false;
                    //RasXLSExpOpts.ShowGridlines = false;
                    //RasXLSExpOpts.StartPageNumber = 3;
                    //RasXLSExpOpts.EndPageNumber = 10;
                    //RASXLXSExportOpts.ConstantColWidth = Convert.ToInt32(36.6);
                    //RASXLXSExportOpts.ExportObjectFormatting = true;
                    //RASXLXSExportOpts.ExportImages = false;
                    //RASXLXSExportOpts.UseWorksheetFunctionsForSummaries = false;
                    //RASXLXSExportOpts.MaintainRelativeObjectPosition = true;
                    //RASXLXSExportOpts.MaintainColumnAlignment = true;
                    //RASXLXSExportOpts.ExportPageHeaderAndFooter = false;
                    //RASXLXSExportOpts.SimplifyPageHeaders = true;
                    //RASXLXSExportOpts.ShowGroupOutlines = false;
                    // Save the udpated info
                    //rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPageToXLSX, RASXLXSExportOpts);

                    CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
                    exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatPageToXLSX;
                    exportOpts1.FormatOptions = RASXLXSExportOpts;
                    // And Export
                    rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
                    MessageBox.Show("Export to Excel XLXS Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    btnSQLStatement.Text = "ERROR: " + ex.Message;
                    return;
                }
            }// new in SP30
            #endregion MSPageXLSX