mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
handle Excel limits (#23321)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { Action } from 'vs/base/common/actions';
|
import { Action, toAction } from 'vs/base/common/actions';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import { Table } from 'sql/base/browser/ui/table/table';
|
import { Table } from 'sql/base/browser/ui/table/table';
|
||||||
@@ -23,6 +23,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
|||||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||||
import { getChartMaxRowCount, notifyMaxRowCountExceeded } from 'sql/workbench/contrib/charts/browser/utils';
|
import { getChartMaxRowCount, notifyMaxRowCountExceeded } from 'sql/workbench/contrib/charts/browser/utils';
|
||||||
import { IEncodingSupport } from 'vs/workbench/services/textfile/common/textfiles';
|
import { IEncodingSupport } from 'vs/workbench/services/textfile/common/textfiles';
|
||||||
|
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||||
|
|
||||||
export interface IGridActionContext {
|
export interface IGridActionContext {
|
||||||
gridDataProvider: IGridDataProvider;
|
gridDataProvider: IGridDataProvider;
|
||||||
@@ -43,6 +44,10 @@ function mapForNumberColumn(ranges: Slick.Range[]): Slick.Range[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ExcelSpecUrl = 'https://support.microsoft.com/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3';
|
||||||
|
const ExcelRowLimit: number = 1048576;
|
||||||
|
const ExcelColumnLimit: number = 16384;
|
||||||
|
|
||||||
export class SaveResultAction extends Action {
|
export class SaveResultAction extends Action {
|
||||||
public static SAVECSV_ID = 'grid.saveAsCsv';
|
public static SAVECSV_ID = 'grid.saveAsCsv';
|
||||||
public static SAVECSV_LABEL = localize('saveAsCsv', "Save As CSV");
|
public static SAVECSV_LABEL = localize('saveAsCsv', "Save As CSV");
|
||||||
@@ -71,11 +76,35 @@ export class SaveResultAction extends Action {
|
|||||||
private format: SaveFormat,
|
private format: SaveFormat,
|
||||||
@INotificationService private notificationService: INotificationService,
|
@INotificationService private notificationService: INotificationService,
|
||||||
@IEditorService private editorService: IEditorService,
|
@IEditorService private editorService: IEditorService,
|
||||||
|
@IOpenerService private openerService: IOpenerService
|
||||||
) {
|
) {
|
||||||
super(id, label, icon);
|
super(id, label, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async run(context: IGridActionContext): Promise<void> {
|
public override async run(context: IGridActionContext): Promise<void> {
|
||||||
|
if (!context.gridDataProvider.canSerialize) {
|
||||||
|
this.notificationService.warn(localize('saveToFileNotSupported', "Save to file is not supported by the backing data source"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.format === SaveFormat.EXCEL && (context.table.getData().getLength() > ExcelRowLimit || context.table.columns.length > ExcelColumnLimit)) {
|
||||||
|
this.notificationService.notify({
|
||||||
|
severity: Severity.Error,
|
||||||
|
message: localize('excelLimitExceededError', "The number of rows or columns in the table has exceeded the Excel limits. Please try a different format instead."),
|
||||||
|
actions: {
|
||||||
|
primary: [
|
||||||
|
toAction({
|
||||||
|
id: 'openExcelSpecs',
|
||||||
|
label: localize('openExcelSpecs', "View Excel specifications"),
|
||||||
|
run: () => {
|
||||||
|
this.openerService.open(ExcelSpecUrl);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const activeEditor = this.editorService.activeEditorPane as unknown as IEncodingSupport;
|
const activeEditor = this.editorService.activeEditorPane as unknown as IEncodingSupport;
|
||||||
if (typeof activeEditor.getEncoding === 'function' && activeEditor.getEncoding() !== 'utf8') {
|
if (typeof activeEditor.getEncoding === 'function' && activeEditor.getEncoding() !== 'utf8') {
|
||||||
@@ -86,10 +115,6 @@ export class SaveResultAction extends Action {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.gridDataProvider.canSerialize) {
|
|
||||||
this.notificationService.warn(localize('saveToFileNotSupported', "Save to file is not supported by the backing data source"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await context.gridDataProvider.serializeResults(this.format, mapForNumberColumn(context.selection));
|
await context.gridDataProvider.serializeResults(this.format, mapForNumberColumn(context.selection));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user