Skip to content

@memberjunction/ng-export-service

Angular service and dialog component for exporting data to Excel, CSV, and JSON formats, with configurable sampling, column selection, and browser-side file download.

The @memberjunction/ng-export-service package wraps the @memberjunction/export-engine for Angular usage. It provides an injectable ExportService with format-specific convenience methods and an ExportDialogComponent that presents a progressive UI for format selection, row sampling, and one-click download.

flowchart LR
    subgraph Dialog["ExportDialogComponent"]
        FMT[Format Selection] --> SAMP[Sampling Options]
        SAMP --> PREV[Row Estimate Preview]
        PREV --> DL[Export & Download]
    end

    subgraph Service["ExportService"]
        EXP[export / toExcel / toCSV / toJSON]
        DOWN[downloadResult]
        BOTH[exportAndDownload]
    end

    subgraph Engine["@memberjunction/export-engine"]
        EE[ExportEngine]
    end

    Dialog --> Service
    Service --> Engine

    style Dialog fill:#2d6a9f,stroke:#1a4971,color:#fff
    style Service fill:#7c5295,stroke:#563a6b,color:#fff
    style Engine fill:#2d8659,stroke:#1a5c3a,color:#fff
Terminal window
npm install @memberjunction/ng-export-service
import { ExportServiceModule } from '@memberjunction/ng-export-service';
@NgModule({
imports: [ExportServiceModule]
})
export class YourModule { }
@if (showExportDialog) {
<mj-export-dialog
[visible]="showExportDialog"
[config]="exportConfig"
(closed)="onExportDialogClosed($event)">
</mj-export-dialog>
}
import { ExportDialogConfig, ExportDialogResult } from '@memberjunction/ng-export-service';
@Component({ ... })
export class MyComponent {
showExportDialog = false;
exportConfig: ExportDialogConfig | null = null;
openExport(data: Record<string, unknown>[]) {
this.exportConfig = {
data,
defaultFileName: 'contacts-export',
defaultFormat: 'excel',
showSamplingOptions: true,
dialogTitle: 'Export Contacts'
};
this.showExportDialog = true;
}
onExportDialogClosed(result: ExportDialogResult) {
this.showExportDialog = false;
if (result.exported) {
console.log('Exported successfully:', result.result?.fileName);
}
}
}
import { ExportService } from '@memberjunction/ng-export-service';
import { ExportData } from '@memberjunction/export-engine';
@Component({ ... })
export class MyComponent {
private exportService = inject(ExportService);
async exportToExcel(data: ExportData) {
// Export and immediately trigger browser download
const result = await this.exportService.exportAndDownload(data, {
format: 'excel',
fileName: 'my-data',
includeHeaders: true
});
if (!result.success) {
console.error('Export failed:', result.error);
}
}
async exportToCSV(data: ExportData) {
// Export with sampling -- only first 500 rows
const result = await this.exportService.toCSV(data, {
fileName: 'sample-data',
sampling: { mode: 'top', count: 500 }
});
if (result.success) {
this.exportService.downloadResult(result);
}
}
}

Root-provided Angular service wrapping ExportEngine.

MethodReturnsDescription
export(data, options?)Promise<ExportResult>Export data with full options
toExcel(data, options?)Promise<ExportResult>Export to Excel format
toCSV(data, options?)Promise<ExportResult>Export to CSV format
toJSON(data, options?)Promise<ExportResult>Export to JSON format
getSupportedFormats()ExportFormat[]List supported formats
downloadResult(result)voidTrigger browser file download
exportAndDownload(data, options?)Promise<ExportResult>Export then download in one call
getSamplingModes()SamplingModeInfo[]Get sampling modes with labels
getFormatInfo(format)FormatInfoGet format label, icon, description
buildSamplingOptions(mode, count?, interval?)SamplingOptionsBuild sampling config from user selections

Standalone export dialog with progressive UX.

InputTypeDefaultDescription
visiblebooleanfalseControls dialog visibility
configExportDialogConfig | nullnullDialog configuration
OutputTypeDescription
closedEventEmitter<ExportDialogResult>Emitted when dialog closes
interface ExportDialogConfig {
data: ExportData;
columns?: ExportColumn[];
defaultFileName?: string;
availableFormats?: ExportFormat[];
defaultFormat?: ExportFormat;
showSamplingOptions?: boolean;
defaultSamplingMode?: SamplingMode;
defaultSampleCount?: number;
dialogTitle?: string;
}
interface ExportDialogResult {
exported: boolean;
result?: ExportResult;
options?: ExportOptions;
}
ModeDescription
allExport all data rows
topExport the first N rows
bottomExport the last N rows
every-nthExport every Nth row
randomExport N random rows
PackageDescription
@memberjunction/export-engineCore export engine with format support
  • @angular/common ^21.x
  • @angular/core ^21.x
  • @angular/forms ^21.x
  • @angular/cdk ^21.x

Note: For export types (ExportFormat, ExportOptions, ExportResult, etc.), import directly from @memberjunction/export-engine.

Terminal window
cd packages/Angular/Generic/export-service
npm run build

ISC