mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 10:38:31 -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 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;
|
||||
columns: azdata.IDbColumn[];
|
||||
includeHeaders?: boolean;
|
||||
@@ -157,7 +157,7 @@ export class SerializationService implements ISerializationService {
|
||||
|
||||
private createStartRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataStartRequestParams {
|
||||
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 => {
|
||||
// For now treat all as strings. In the future, would like to use the
|
||||
// type info for correct data type mapping
|
||||
@@ -186,7 +186,7 @@ export class SerializationService implements ISerializationService {
|
||||
|
||||
private createContinueRequest(serializationRequest: SerializeDataParams, index: number): azdata.SerializeDataContinueRequestParams {
|
||||
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 continueSerializeRequest: azdata.SerializeDataContinueRequestParams = {
|
||||
filePath: serializationRequest.filePath,
|
||||
|
||||
@@ -325,7 +325,7 @@ class DataResourceDataProvider implements IGridDataProvider {
|
||||
maxRow = singleSelection.toRow + 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
|
||||
index = index + minRow;
|
||||
if (rowLength === 0 || index < 0 || index >= maxRow) {
|
||||
@@ -335,12 +335,25 @@ class DataResourceDataProvider implements IGridDataProvider {
|
||||
if (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)) {
|
||||
return row.slice(singleSelection.fromCell, singleSelection.toCell + 1);
|
||||
} else {
|
||||
return row;
|
||||
}
|
||||
return row;
|
||||
});
|
||||
}));
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -348,7 +361,7 @@ class DataResourceDataProvider implements IGridDataProvider {
|
||||
saveFormat: format,
|
||||
columns: columns,
|
||||
filePath: filePath.fsPath,
|
||||
getRowRange: (rowStart, numberOfRows) => getRows(rowStart, numberOfRows),
|
||||
getRowRange: (rowStart, includeHeaders, numberOfRows) => getRows(rowStart, includeHeaders, numberOfRows),
|
||||
rowCount: rowLength
|
||||
});
|
||||
return this._serializationService.serializeResults(serializeRequestParams);
|
||||
|
||||
Reference in New Issue
Block a user