on 2022 Mar 03 7:45 PM
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)
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can save the info in CRD or use this or both:
if (ExportTypeSelected == "crReportExportFormatMSExcel")
#region MSExcel
{
// 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)) + "xls";
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions RasXLSExpOpts = new ExcelExportFormatOptions();
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel);
btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RasXLSExpOpts.BaseAreaGroupNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - BaseAreaType: " + RasXLSExpOpts.BaseAreaType.ToString() + "\n";
btnReportObjects.Text += "Excel - FormulaExportPageAreaType: " + RasXLSExpOpts.ExportPageAreaPairType.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageBreaks: " + RasXLSExpOpts.ExportPageBreaks.ToString() + "\n";
btnReportObjects.Text += "Excel - ConstantColWidth: " + RasXLSExpOpts.ConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ConvertDatesToStrings: " + RasXLSExpOpts.ConvertDatesToStrings.ToString() + "\n";
btnReportObjects.Text += "Excel - StartPageNumber: " + RasXLSExpOpts.StartPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - EndPageNumber: " + RasXLSExpOpts.EndPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageBreaks: " + RasXLSExpOpts.ExportPageBreaks.ToString() + "\n";
btnReportObjects.Text += "Excel - MRelativeObjectPosition: " + RasXLSExpOpts.MaintainRelativeObjectPosition.ToString() + "\n";
btnReportObjects.Text += "Excel - ShowGridlines: " + RasXLSExpOpts.ShowGridlines.ToString() + "\n";
btnReportObjects.Text += "Excel - UseConstantColWidth: " + RasXLSExpOpts.UseConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ExcelTabHasColumnHeadings: " + RasXLSExpOpts.ExcelTabHasColumnHeadings + "\n";
try
{
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToMSExcel);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
//return;
}
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
RasXLSExpOpts.ExcelTabHasColumnHeadings = true;
// Save the udpated info
rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel, RasXLSExpOpts);
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSExcel;
exportOpts1.FormatOptions = RasXLSExpOpts;
// Show start time
DateTime dtStart;
TimeSpan difference;
dtStart = DateTime.Now;
btnReportObjects.Text += "Report Export Started: " + dtStart + "\r\n";
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
difference = DateTime.Now.Subtract(dtStart);
btnReportObjects.Text += "Report Export Completed in: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + "\r\n";
MessageBox.Show("Export to Excel Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
// This works do not alter
}
#endregion MSExcel
if (ExportTypeSelected == "crReportExportFormatXLSX")
#region XLSX
{
// 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
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.DataOnlyExcelExportFormatOptions RASXLXSExportOpts = new DataOnlyExcelExportFormatOptions();
RASXLXSExportOpts = (DataOnlyExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX);
//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 - Export Images: " + RASXLXSExportOpts.ExportImages.ToString() + "\n";
//btnReportObjects.Text += "Excel - ExportObject Formatting: " + RASXLXSExportOpts.ExportObjectFormatting.ToString() + "\n";
//btnReportObjects.Text += "Excel - Export Page Header Footer: " + RASXLXSExportOpts.ExportPageHeaderAndFooter.ToString() + "\n";
//btnReportObjects.Text += "Excel - Maintain Column Alignment: " + RASXLXSExportOpts.MaintainColumnAlignment.ToString() + "\n";
//btnReportObjects.Text += "Excel - MaintainRelativeObjectPos: " + RASXLXSExportOpts.MaintainRelativeObjectPosition.ToString() + "\n";
//btnReportObjects.Text += "Excel - ShowGroupOutlines: " + RASXLXSExportOpts.ShowGroupOutlines.ToString() + "\n";
//btnReportObjects.Text += "Excel - SimplifyPageHeaders: " + RASXLXSExportOpts.SimplifyPageHeaders.ToString() + "\n";
//btnReportObjects.Text += "Excel - UseConstantColWidth: " + RASXLXSExportOpts.UseConstantColWidth.ToString() + "\n";
//btnReportObjects.Text += "Excel - UseWorkstFuncForSummaries: " + RASXLXSExportOpts.UseWorksheetFunctionsForSummaries.ToString() + "\n";
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
try
{
RASXLXSExportOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
//return;
}
// Save the udpated info
//rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX, RASXLXSExportOpts);
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatXLSX;
exportOpts1.FormatOptions = RASXLXSExportOpts;
// Manually set the values
//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;
CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions ExpXLXSOpts = new ExcelExportFormatOptions();
//ExpXLXSOpts.ConstantColWidth = 45;
//ExpXLXSOpts.ConvertDatesToStrings = true;
exportOpts1.ExportOptionsEx = null;
// 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;
}
}
#endregion XLSX
if (ExportTypeSelected == "crReportExportFormatRecordToXLSX") // new in SP30
#region MSRecordExcel
{
// 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.DataOnlyExcelExportFormatOptions RasXLSExpOpts = (DataOnlyExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToXLSX); //new API, introduced from BI 4.3 SP02 And Cortez SP30
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToXLSX);
if (RasXLSExpOpts != null)
{
btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RasXLSExpOpts.BaseAreaGroupNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - BaseAreaType: " + RasXLSExpOpts.BaseAreaType.ToString() + "\n";
btnReportObjects.Text += "Excel - ConstantColWidth: " + RasXLSExpOpts.ConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportImages: " + RasXLSExpOpts.ExportImages.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportObjectFormatting: " + RasXLSExpOpts.ExportObjectFormatting.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportObjectFormatting: " + RasXLSExpOpts.ExportObjectFormatting.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageHeaderAndFooter: " + RasXLSExpOpts.ExportPageHeaderAndFooter.ToString() + "\n";
btnReportObjects.Text += "Excel - MaintainColumnAlignment: " + RasXLSExpOpts.MaintainColumnAlignment.ToString() + "\n";
btnReportObjects.Text += "Excel - MaintainRelativeObjectPosition: " + RasXLSExpOpts.MaintainRelativeObjectPosition.ToString() + "\n";
btnReportObjects.Text += "Excel - ShowGroupOutlines: " + RasXLSExpOpts.ShowGroupOutlines.ToString() + "\n";
btnReportObjects.Text += "Excel - SimplifyPageHeaders: " + RasXLSExpOpts.SimplifyPageHeaders.ToString() + "\n";
btnReportObjects.Text += "Excel - UseConstantColWidth: " + RasXLSExpOpts.UseConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - UseWorksheetFunctionsForSummaries: " + RasXLSExpOpts.UseWorksheetFunctionsForSummaries+ "\n";
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
//RasXLSExpOpts.ExcelTabHasColumnHeadings = true;
// Save the udpated info
//rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel, RasXLSExpOpts);
}
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatRecordToXLSX;
exportOpts1.FormatOptions = RasXLSExpOpts;
// Show start time
DateTime dtStart;
TimeSpan difference;
dtStart = DateTime.Now;
btnReportObjects.Text += "Report Export Started: " + dtStart + "\r\n";
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
difference = DateTime.Now.Subtract(dtStart);
btnReportObjects.Text += "Report Export Completed in: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + "\r\n";
MessageBox.Show("Export to MicrosoftExcel(XLS) Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
// This works do not alter
} // new in SP30
#endregion MSRecordExcel
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the Report Designer click on the Export button and select Report Export Options, select the destination etc. and fill in the default values.
Save the report, see if that works for you.
Also, Search for Optimizing export to Excel, should be a KBA on how to, and see if that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Don.
My question is not in Crystal Designer, because in Crystal Designer I can configure the export to Excel using the width of the columns in the Details section.
I would like to know how to set the export to Excel in a .NET application using the Crystal SDK.
What are the commands to configure the export using the width of the columns in the Details section?
Try searching in CR Design forum for export empty columns and you may find one on how to.
Exporting from .NET or CR should be the same
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Don, how are you?
Thanks for the feedback.
Unfortunately, the behavior of CR Design in the export part is different than when using the SDK.
I searched on the Forum and found several complaints in this regard, because the SDK no longer presents the "Export Options Screen" and when exporting it only shows the "Path\Filename" screen, creating columns for Excel layout adjustments and not allowing you to remove these columns.
In one of the comments that I found, SAP says that the SDK actually no longer has the options screen, indicates to the user to create your own export routine (Links sent previously and that are broken)
This is a picture comparing the Excel file generated with the old version (left side) and the new version (right side)
Notice that there are many more columns on the right side.
Thank you for your support and understanding.
User | Count |
---|---|
40 | |
15 | |
10 | |
8 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.