本文整理汇总了C#中SpreadsheetDocument.Close方法的典型用法代码示例。如果您正苦于以下问题:C# SpreadsheetDocument.Close方法的具体用法?C# SpreadsheetDocument.Close怎么用?C# SpreadsheetDocument.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpreadsheetDocument
的用法示例。
在下文中一共展示了SpreadsheetDocument.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LerPlanilhaDados
public List<object[]> LerPlanilhaDados(Stream stream)
{
List<object[]> dadosPlanilha = new List<object[]>();
using (_document = SpreadsheetDocument.Open(stream, true))
{
try
{
_wbPart = _document.WorkbookPart;
_sharedStringPart = GetSharedStringPart();
if (SelectFirstSheet())
{
int indice = 0;
foreach (Row row in _activeWorksheet.Descendants<Row>())
{
indice++;
if (indice == 1) continue; // Pula o cabeçalho.
List<object> dadosLinha = new List<object>();
foreach (Cell celula in row.Descendants<Cell>())
dadosLinha.Add(GetCellValue(celula));
dadosPlanilha.Add(dadosLinha.ToArray());
}
}
}
catch
{
throw;
}
finally
{
_document.Close();
}
return dadosPlanilha;
}
}
示例2: AddDataTuplesToTemplate
/// <summary>
/// Add Datatuples to a Excel Template file
/// </summary>
/// <remarks></remarks>
/// <seealso cref=""/>
/// <param name="dataTuples"> Datatuples to add</param>
/// <param name="filePath">Path of the excel template file</param>
/// <param name="dataStructureId">Id of datastructure</param>
/// <returns>List of Errors or null</returns>
public List<Error> AddDataTuplesToTemplate(DatasetManager datasetManager, List<long> dataTuplesIds, string filePath, long dataStructureId )
{
if (File.Exists(filePath))
{
//Stream file = Open(filePath);
//_dataTuples = dataTuples;
// loading datastructure
dataStructure = GetDataStructure(dataStructureId);
// open excel file
spreadsheetDocument = SpreadsheetDocument.Open(filePath, true);
// get workbookpart
WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
// get all the defined area
List<DefinedNameVal> namesTable = buildDefinedNamesTable(workbookPart);
// select data area
this.areaOfData = namesTable.Where(p => p.Key.Equals("Data")).FirstOrDefault();
// Select variable area
this.areaOfVariables = namesTable.Where(p => p.Key.Equals("VariableIdentifiers")).FirstOrDefault();
// Get intergers for reading data
startColumn = getColumnNumber(this.areaOfData.StartColumn);
endColumn = getColumnNumber(this.areaOfData.EndColumn);
numOfColumns = (endColumn - startColumn) + 1;
offset = getColumnNumber(getColumnName(this.areaOfData.StartColumn)) - 1;
// gerneat Style for cell types
generateStyle(spreadsheetDocument);
// get styleSheet
stylesheet = workbookPart.WorkbookStylesPart.Stylesheet;
// Get shared strings
sharedStrings = workbookPart.SharedStringTablePart.SharedStringTable.Elements<SharedStringItem>().ToArray();
// select worksheetpart by selected defined name area like data in sheet
// sheet where data area is inside
WorksheetPart worksheetPart = getWorkSheetPart(workbookPart, this.areaOfData);
// Get VarioableIndentifiers
this.VariableIdentifiers = getVariableIdentifiers(worksheetPart, this.areaOfVariables.StartRow, this.areaOfVariables.EndRow);
AddRows(worksheetPart, this.areaOfData.StartRow, this.areaOfData.EndRow, dataTuplesIds, datasetManager);
// set data area
foreach (DefinedName name in workbookPart.Workbook.GetFirstChild<DefinedNames>())
{
if (name.Name == "Data")
{
string[] tempArr = name.InnerText.Split('$');
string temp = "";
//$A$10:$C$15
tempArr[tempArr.Count() - 1] = numOfDataRows.ToString();
foreach (string t in tempArr)
{
if (t == tempArr.First())
{
temp = temp + t;
}
else
{
temp = temp + "$" + t;
}
}
name.Text = temp;
}
}
spreadsheetDocument.WorkbookPart.Workbook.Save();
spreadsheetDocument.Close();
}
return ErrorMessages;
}
示例3: Save
public override void Save(ResearchResult result)
{
if (!Directory.Exists(storageStr))
{
Directory.CreateDirectory(storageStr);
}
string fileName = storageStr + result.ResearchName;
if (File.Exists(fileName + ".xls") || File.Exists(fileName + ".xlsx"))
fileName += result.ResearchID;
document = SpreadsheetDocument.Create(fileName + ".xlsx", SpreadsheetDocumentType.Workbook);
workbook = document.AddWorkbookPart();
workbook.Workbook = new Workbook();
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart worksheetPart = workbook.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Add Sheets to the Workbook.
Sheets sheets = document.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
// Append a new worksheet and associate it with the workbook.
Sheet sheet = new Sheet()
{
Id = document.WorkbookPart.
GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "mySheet"
};
sheets.Append(sheet);
/*SaveResearchInfo(result.ResearchID, result.ResearchName,
result.ResearchType, result.ModelType, result.RealizationCount,
result.Size, result.Edges);
SaveResearchParameters(result.ResearchParameterValues);
SaveGenerationParameters(result.GenerationParameterValues);
for (int i = 0; i < result.EnsembleResults.Count; ++i)
{
SaveEnsembleResult(result.EnsembleResults[i], i);
}*/
workbook.Workbook.Save();
document.Close();
}
示例4: PreencherPlanilha
//.........这里部分代码省略.........
#region Garantia, Documentação Apresentada e Observações
//SelecionarOpcao(laudo.AceitoComoGarantia == 0 ? "GarSim" : "GarNao");
PreencherCampo("B37", laudo.MatriculaRGI);
PreencherCampo("I37", laudo.Oficio);
PreencherCampo("T37", laudo.Comarca == null ? string.Empty : laudo.Comarca.Nome);
PreencherCampo("B40", laudo.OutrosDocumentos);
//SelecionarOpcao(laudo.Conformidade == 0 ? "DocSim" : "DocNao");
PreencherCampo("C45", laudo.Divergencia);
PreencherCampo("C49", laudo.ObservacoesFinais);
#endregion
#region Rodapé
if (configuracao != null)
PreencherCampo("G69", string.Format("{0} / {1}", configuracao.NomeEmpresa, configuracao.CNPJEmpresa));
if (!string.IsNullOrEmpty(laudo.LocalEmissaoLaudo))
PreencherCampo("B72", string.Format("{0} / {1}", laudo.LocalEmissaoLaudo, DateTime.Now.Date.ToString("dd/MM/yyyy")));
if (laudo.ResponsavelTecnico != null)
{
PreencherCampo("E75", string.Format("{0} / {1}", laudo.ResponsavelTecnico.Nome.ToUpper(), laudo.ResponsavelTecnico.CREA));
PreencherCampo("E76", laudo.ResponsavelTecnico.CPF);
}
if (laudo.RepresentanteLegalEmpresa != null)
{
PreencherCampo("T75", laudo.RepresentanteLegalEmpresa.Nome.ToUpper());
PreencherCampo("T76", laudo.RepresentanteLegalEmpresa.CPF);
}
#endregion
}
#endregion
#region Laudo fl 3
if (SelectSheet("Laudo fl 3"))
{
#region Cabeçalho
PreencherCampo("L6", laudo.Solicitante);
PreencherCampo("W6", laudo.Referencia);
#endregion
#region Identificação
if (laudo.Produto != null)
PreencherCampo("B10", laudo.Produto.Descricao);
if (laudo.Linha != null)
PreencherCampo("W10", laudo.Linha.Descricao);
if (laudo.Fonte != null)
PreencherCampo("B13", laudo.Fonte.Descricao);
PreencherCampo("B16", laudo.Imovel.NomeCliente);
PreencherCampo("W16", laudo.Imovel.TipoLogradouro.Descricao);
PreencherCampo("B19", string.Format("{0}, {1}", laudo.Imovel.Endereco, laudo.Imovel.Numero));
PreencherCampo("W19", laudo.Imovel.Complemento);
PreencherCampo("B22", laudo.Imovel.Bairro);
PreencherCampo("W22", laudo.Imovel.Cidade.Nome);
PreencherCampo("AH22", laudo.Imovel.Cidade.Estado.Sigla);
#endregion
#region Rodapé
if (configuracao != null)
PreencherCampo("G34", string.Format("{0} / {1}", configuracao.NomeEmpresa, configuracao.CNPJEmpresa));
if (!string.IsNullOrEmpty(laudo.LocalEmissaoLaudo))
PreencherCampo("B37", string.Format("{0} / {1}", laudo.LocalEmissaoLaudo, DateTime.Now.Date.ToString("dd/MM/yyyy")));
if (laudo.ResponsavelTecnico != null)
{
PreencherCampo("E40", string.Format("{0} / {1}", laudo.ResponsavelTecnico.Nome.ToUpper(), laudo.ResponsavelTecnico.CREA));
PreencherCampo("E41", laudo.ResponsavelTecnico.CPF);
}
if (laudo.RepresentanteLegalEmpresa != null)
{
PreencherCampo("T40", laudo.RepresentanteLegalEmpresa.Nome.ToUpper());
PreencherCampo("T41", laudo.RepresentanteLegalEmpresa.CPF);
}
#endregion
}
#endregion
}
catch
{
throw;
}
finally
{
_document.Close();
}
}
}
示例5: CreateParts
// Adds child parts and generates content of the specified part
private static void CreateParts(SpreadsheetDocument document)
{
// Create a spreadsheet document by supplying the filepath.
// By default, AutoSave = true, Editable = true, and Type = xlsx.
// Add a WorkbookPart to the document.
WorkbookPart starterWorkbookPart = document.AddWorkbookPart();
starterWorkbookPart.Workbook = new Workbook();
starterWorkbookPart.Workbook.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart starterWorksheetPart = starterWorkbookPart.AddNewPart<WorksheetPart>();
// SheetData: Represents a cell table. Expresses information about each cell, grouped together by rows in the worksheet.
starterWorksheetPart.Worksheet = new Worksheet(new SheetData());
// Add Sheets to the Workbook.
Sheets firstSheets = document.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
// Append a new worksheet and associate it with the workbook.
Sheet leadingSheet = new Sheet()
{
Id = document.WorkbookPart.GetIdOfPart(starterWorksheetPart),
SheetId = 1,
Name = "Sheet1"
};
firstSheets.Append(leadingSheet);
// Save the document
starterWorkbookPart.Workbook.Save();
// Close the document
document.Close();
}