mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 17:23:32 -05:00
* Initial changes to have serialization generate its own .exe * Removed additional project from sln file * remove all references to removed temporary project * Moved shared contracts into own dll and fixed imports. Addressed PR comments * Undid having a separate contracts project since that'll be a task for later on. Moved dbcellvalue and saveresultsrequest to Hosting, where they will be imported and shared by the service layer and serialization projects * Switched backslashes in project reference in csproj file to forward slashes for consistency * Moved necessary contracts back to service layer. Refactored CommandOptions to reduce code duplication. Addressed miscellaneous PR suggestions * Accidentally left these files out of previous commit * Initialized loggers for serialization and credentials with the logging directory provided by the cmd line arg, if there is one * Changed default log directory paths for serialization and credentials. Removed unnecessary cast and added a copyright * Changed name of generated executable for serialization service * removed unnecessary object cast * removing unnecessary imports and addressing other PR comments
87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
|
{
|
|
/// <summary>
|
|
/// Writer for writing rows of results to a Excel file
|
|
/// </summary>
|
|
public class SaveAsExcelFileStreamWriter : SaveAsStreamWriter
|
|
{
|
|
|
|
#region Member Variables
|
|
|
|
private readonly SaveResultsAsExcelRequestParams saveParams;
|
|
private bool headerWritten;
|
|
private SaveAsExcelFileStreamWriterHelper helper;
|
|
private SaveAsExcelFileStreamWriterHelper.ExcelSheet sheet;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Constructor, stores the Excel specific request params locally, chains into the base
|
|
/// constructor
|
|
/// </summary>
|
|
/// <param name="stream">FileStream to access the Excel file output</param>
|
|
/// <param name="requestParams">Excel save as request parameters</param>
|
|
public SaveAsExcelFileStreamWriter(Stream stream, SaveResultsAsExcelRequestParams requestParams)
|
|
: base(stream, requestParams)
|
|
{
|
|
saveParams = requestParams;
|
|
helper = new SaveAsExcelFileStreamWriterHelper(stream);
|
|
sheet = helper.AddSheet();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes a row of data as a Excel row. If this is the first row and the user has requested
|
|
/// it, the headers for the column will be emitted as well.
|
|
/// </summary>
|
|
/// <param name="row">The data of the row to output to the file</param>
|
|
/// <param name="columns">
|
|
/// The entire list of columns for the result set. They will be filtered down as per the
|
|
/// request params.
|
|
/// </param>
|
|
public override void WriteRow(IList<DbCellValue> row, IList<DbColumnWrapper> columns)
|
|
{
|
|
int columnStart = ColumnStartIndex ?? 0;
|
|
int columnEnd = (ColumnEndIndex != null) ? ColumnEndIndex.Value + 1 : columns.Count;
|
|
|
|
// Write out the header if we haven't already and the user chose to have it
|
|
if (saveParams.IncludeHeaders && !headerWritten)
|
|
{
|
|
sheet.AddRow();
|
|
for (int i = columnStart; i < columnEnd; i++)
|
|
{
|
|
sheet.AddCell(columns[i].ColumnName);
|
|
}
|
|
headerWritten = true;
|
|
}
|
|
|
|
sheet.AddRow();
|
|
for (int i = columnStart; i < columnEnd; i++)
|
|
{
|
|
sheet.AddCell(row[i]);
|
|
}
|
|
}
|
|
|
|
private bool disposed;
|
|
override protected void Dispose(bool disposing)
|
|
{
|
|
if (disposed)
|
|
return;
|
|
|
|
sheet.Dispose();
|
|
helper.Dispose();
|
|
|
|
disposed = true;
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
}
|
|
} |