mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix Notebook data export to excel/csv not including headers (#11491)
* added includeHeaders param when getting rows * fix spacing * fix syntax and use of map
This commit is contained in:
@@ -28,7 +28,7 @@ export interface SerializeDataParams {
|
|||||||
* @param rowStart Index in the array to start copying rows from
|
* @param rowStart Index in the array to start copying rows from
|
||||||
* @param numberOfRows Total number of rows to copy. If 0 or undefined, will copy all
|
* @param numberOfRows Total number of rows to copy. If 0 or undefined, will copy all
|
||||||
*/
|
*/
|
||||||
getRowRange(rowStart: number, numberOfRows?: number): azdata.DbCellValue[][];
|
getRowRange(rowStart: number, includeHeaders: boolean, numberOfRows?: number): azdata.DbCellValue[][];
|
||||||
rowCount: number;
|
rowCount: number;
|
||||||
columns: azdata.IDbColumn[];
|
columns: azdata.IDbColumn[];
|
||||||
includeHeaders?: boolean;
|
includeHeaders?: boolean;
|
||||||
@@ -157,7 +157,7 @@ export class SerializationService implements ISerializationService {
|
|||||||
|
|
||||||
private createStartRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataStartRequestParams {
|
private createStartRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataStartRequestParams {
|
||||||
let batchSize = getBatchSize(serializationRequest.rowCount, index);
|
let batchSize = getBatchSize(serializationRequest.rowCount, index);
|
||||||
let rows = serializationRequest.getRowRange(index, batchSize);
|
let rows = serializationRequest.getRowRange(index, serializationRequest.includeHeaders, batchSize);
|
||||||
let columns: azdata.SimpleColumnInfo[] = serializationRequest.columns.map(c => {
|
let columns: azdata.SimpleColumnInfo[] = serializationRequest.columns.map(c => {
|
||||||
// For now treat all as strings. In the future, would like to use the
|
// For now treat all as strings. In the future, would like to use the
|
||||||
// type info for correct data type mapping
|
// type info for correct data type mapping
|
||||||
@@ -186,7 +186,7 @@ export class SerializationService implements ISerializationService {
|
|||||||
|
|
||||||
private createContinueRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataContinueRequestParams {
|
private createContinueRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataContinueRequestParams {
|
||||||
let numberOfRows = getBatchSize(serializationRequest.rowCount, index);
|
let numberOfRows = getBatchSize(serializationRequest.rowCount, index);
|
||||||
let rows = serializationRequest.getRowRange(index, numberOfRows);
|
let rows = serializationRequest.getRowRange(index, serializationRequest.includeHeaders, numberOfRows);
|
||||||
let isLastBatch = index + rows.length >= serializationRequest.rowCount;
|
let isLastBatch = index + rows.length >= serializationRequest.rowCount;
|
||||||
let continueSerializeRequest: azdata.SerializeDataContinueRequestParams = {
|
let continueSerializeRequest: azdata.SerializeDataContinueRequestParams = {
|
||||||
filePath: serializationRequest.filePath,
|
filePath: serializationRequest.filePath,
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ class DataResourceDataProvider implements IGridDataProvider {
|
|||||||
maxRow = singleSelection.toRow + 1;
|
maxRow = singleSelection.toRow + 1;
|
||||||
columns = columns.slice(singleSelection.fromCell, singleSelection.toCell + 1);
|
columns = columns.slice(singleSelection.fromCell, singleSelection.toCell + 1);
|
||||||
}
|
}
|
||||||
let getRows: ((index: number, rowCount: number) => ICellValue[][]) = (index, rowCount) => {
|
let getRows: ((index: number, includeHeaders: boolean, rowCount: number) => ICellValue[][]) = (index, includeHeaders, rowCount) => {
|
||||||
// Offset for selections by adding the selection startRow to the index
|
// Offset for selections by adding the selection startRow to the index
|
||||||
index = index + minRow;
|
index = index + minRow;
|
||||||
if (rowLength === 0 || index < 0 || index >= maxRow) {
|
if (rowLength === 0 || index < 0 || index >= maxRow) {
|
||||||
@@ -335,12 +335,25 @@ class DataResourceDataProvider implements IGridDataProvider {
|
|||||||
if (endIndex > maxRow) {
|
if (endIndex > maxRow) {
|
||||||
endIndex = maxRow;
|
endIndex = maxRow;
|
||||||
}
|
}
|
||||||
let result = this.rows.slice(index, endIndex).map(row => {
|
let result: ICellValue[][] = [];
|
||||||
|
if (includeHeaders) {
|
||||||
|
result.push(columns.map(col => {
|
||||||
|
let headerData: azdata.DbCellValue;
|
||||||
|
headerData = {
|
||||||
|
displayValue: col.columnName,
|
||||||
|
isNull: false,
|
||||||
|
invariantCultureDisplayValue: col.columnName
|
||||||
|
};
|
||||||
|
return headerData;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
result = result.concat(this.rows.slice(index, endIndex).map(row => {
|
||||||
if (this.isSelected(singleSelection)) {
|
if (this.isSelected(singleSelection)) {
|
||||||
return row.slice(singleSelection.fromCell, singleSelection.toCell + 1);
|
return row.slice(singleSelection.fromCell, singleSelection.toCell + 1);
|
||||||
|
} else {
|
||||||
|
return row;
|
||||||
}
|
}
|
||||||
return row;
|
}));
|
||||||
});
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -348,7 +361,7 @@ class DataResourceDataProvider implements IGridDataProvider {
|
|||||||
saveFormat: format,
|
saveFormat: format,
|
||||||
columns: columns,
|
columns: columns,
|
||||||
filePath: filePath.fsPath,
|
filePath: filePath.fsPath,
|
||||||
getRowRange: (rowStart, numberOfRows) => getRows(rowStart, numberOfRows),
|
getRowRange: (rowStart, includeHeaders, numberOfRows) => getRows(rowStart, includeHeaders, numberOfRows),
|
||||||
rowCount: rowLength
|
rowCount: rowLength
|
||||||
});
|
});
|
||||||
return this._serializationService.serializeResults(serializeRequestParams);
|
return this._serializationService.serializeResults(serializeRequestParams);
|
||||||
|
|||||||
Reference in New Issue
Block a user