当前位置: 首页>>代码示例>>C#>>正文


C# SpreadsheetDocument.Close方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:AmandaMakino,项目名称:SisUrbe,代码行数:42,代码来源:OpenXmlHelper.cs

示例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;
        }
开发者ID:BEXIS2,项目名称:Core,代码行数:95,代码来源:ExcelWriter.cs

示例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();
        }
开发者ID:aramazhari,项目名称:complexnetwork,代码行数:47,代码来源:ExcelResultStorage.cs

示例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();
                }
            }
        }
开发者ID:AmandaMakino,项目名称:SisUrbe,代码行数:101,代码来源:OpenXmlHelper.cs

示例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();
        }
开发者ID:esantosrcj,项目名称:OpenXML-Project,代码行数:34,代码来源:CopyXlsx.cs


注:本文中的SpreadsheetDocument.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。