private void FillSheet(string separateBy)
 {
     WriteData(CreateHeader(), separateBy);
     if ((_excelApp.ActiveSheet as _Worksheet).Range["A1"].Value2 != null)
     {
         _sheet = _sheets.Add();
         _sheet.Select();
     }
 }
Exemplo n.º 2
0
        private AnswerSheet CreateAnswerSheetInternalFor(string name)
        {
            AnswerSheet a = new AnswerSheet(name, this);

            Sheets.Add(a);
            return(a);
        }
Exemplo n.º 3
0
        /// <summary>
        /// シートを作成する
        /// ※カレントシートは変更しない
        /// </summary>
        /// <param name="sheetName"></param>
        public void CreateSheet(string sheetName, SheetPosition position)
        {
            Worksheet lastSheet = null;
            Worksheet newSheet  = null;

            try
            {
                lastSheet     = xlSheets[xlSheets.Count];
                newSheet      = xlSheets.Add(After: lastSheet);
                newSheet.Name = sheetName;
                MoveLastSheet(position);
            }finally
            {
                if (newSheet != null)
                {
                    Marshal.ReleaseComObject(newSheet);
                }
                newSheet = null;

                if (lastSheet != null)
                {
                    Marshal.ReleaseComObject(lastSheet);
                }
                lastSheet = null;
            }
        }
Exemplo n.º 4
0
        internal XlsWorkbook(Stream stream, string password, Encoding fallbackEncoding)
        {
            Stream = stream;

            using (var biffStream = new XlsBiffStream(stream, 0, 0, password))
            {
                if (biffStream.BiffVersion == 0)
                {
                    throw new ExcelReaderException(Errors.ErrorWorkbookGlobalsInvalidData);
                }

                BiffVersion = biffStream.BiffVersion;
                SecretKey   = biffStream.SecretKey;
                Encryption  = biffStream.Encryption;
                Encoding    = biffStream.BiffVersion == 8 ? Encoding.Unicode : fallbackEncoding;

                if (biffStream.BiffType == BIFFTYPE.WorkbookGlobals)
                {
                    ReadWorkbookGlobals(biffStream);
                }
                else if (biffStream.BiffType == BIFFTYPE.Worksheet)
                {
                    // set up 'virtual' bound sheet pointing at this
                    Sheets.Add(new XlsBiffBoundSheet(0, XlsBiffBoundSheet.SheetType.Worksheet, XlsBiffBoundSheet.SheetVisibility.Visible, "Sheet"));
                }
                else
                {
                    throw new ExcelReaderException(Errors.ErrorWorkbookGlobalsInvalidData);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Setup workbooks/worksheets and populate them
        /// </summary>
        public void Initialize()
        {
            //_application.Workbooks.add(...) is not possible.
            //2 dots must be avoided to release wrappers: http://support.microsoft.com/kb/317109
            Workbooks workbooks = _application.Workbooks;

            _workbook = workbooks.Add(Missing.Value);

            Sheets worksheets = _workbook.Worksheets;

            _worksheet       = (Worksheet)_workbook.ActiveSheet;
            _worksheetHidden = (Worksheet)worksheets.Add();

            // Release wrapper objects
            Marshal.FinalReleaseComObject(worksheets);
            Marshal.FinalReleaseComObject(workbooks);

            _worksheetHidden.Name    = "Mapping Information";
            _worksheetHidden.Visible = XlSheetVisibility.xlSheetVeryHidden;

            //Event handlers
            _worksheet.Change += Event_ChangeEvent;

            Populate();

            _application.Visible = true; //Show the application after it's populated
        }
        /// <summary>
        /// Adds a new sheet to this book.
        /// </summary>
        public bool AddSheet(string sheetName, int rows, int cols)
        {
            // make sure we have sheets
            ApplyTemplate();
            if (Sheets == null)
            {
                return false;
            }

            // create a new sheet
            var newSheet = new Sheet();

            newSheet.Name = sheetName;

            // add rows and columns to the sheet
            for (int r = 0; r < rows; r++)
            {
                newSheet.Grid.Rows.Add(new ExcelRow());
            }
            for (int c = 0; c < cols; c++)
            {
                newSheet.Grid.Columns.Add(new Column());
            }

            // add sheet to grid, select it
            Sheets.Add(newSheet);
            Sheets.SelectedSheet = newSheet;

            // done
            return true;
        }
 public void AddStyleSheets(params StyleSheet[] sheets)
 {
     foreach (var sheet in sheets)
     {
         Sheets.Add(sheet);
     }
 }
Exemplo n.º 8
0
        // Método de exportar arquivo excel usando a dll Microsoft.Office.Interop.Excel
        public static void ExportToExcelUsingMicrosoft <T>(T item)
        {
            // Representa o programa excel instalado no PC do usuário
            Application app = new Application();
            // Representa um arquivo excel
            Workbook excelFile = app.Workbooks.Add();
            // Representa as abas dos excel
            Sheets sheets = excelFile.Worksheets;

            // Cria uma aba em específico
            Worksheet usuarioSheet = sheets.Add() as Worksheet;

            usuarioSheet.Name = "Usuários";

            PopulateSheet(usuarioSheet, item);

            // Se houver mais de uma aba, a de usuários terá o foco.
            usuarioSheet.Activate();

            usuarioSheet.Columns.AutoFit();

            app.Visible = true;

            SaveExcelFile(excelFile, "");
        }
Exemplo n.º 9
0
        public static void writeExcel(string fileName)
        {
            /*if (!File.Exists(fileName))
             * {
             *  File.Create(fileName);
             * }*/
            object      obj = System.Reflection.Missing.Value;
            Application app = new Application();

            app.Visible = false;                   //后台运行
            app.Workbooks.Add(obj);
            app.DisplayAlerts = false;             //设置不显示确认修改提示
            Workbook  wb     = app.ActiveWorkbook; //创建workbook,是内存中的excel文件
            Sheets    sheets = wb.Sheets;          //获取workbook中的sheet
            Worksheet ws     = sheets.Add();       //添加一个sheet

            ws.Name = "表一";                        //设置sheet的名字
            ws.Cells[1, 1].Value = "编号";
            ws.Cells[1, 2].Value = "名字";
            ws.Cells[1, 3].Value = "随机数";
            int    j  = 1;
            Random rd = new Random();

            for (int i = 2; i < 10; i++)
            {
                ws.Cells[i, 1].Value = j;
                ws.Cells[i, 2].Value = "张三";
                ws.Cells[i, 3].Value = rd.Next(100, 999);
            }
            //fileName = "@"+fileName;
            ws.SaveAs(fileName);                         //将内存中的文件保存到硬盘中
            wb.Close(false, Type.Missing, Type.Missing); //关闭workbook
            app.Quit();
        }
Exemplo n.º 10
0
        public static Worksheet AddTableToWorkSheet(Workbook wb, System.Data.DataTable t1, string name)
        {
            try
            {
                Sheets    sheets   = wb.Sheets;
                Worksheet newSheet = sheets.Add();
                newSheet.Name = name;
                int iCol = 0;
                foreach (DataColumn c in t1.Columns)
                {
                    iCol++;
                    newSheet.Cells[1, iCol] = c.ColumnName;
                }
                int iRow = 0;
                foreach (DataRow r in t1.Rows)
                {
                    iRow++;
                    // add each row's cell data...
                    iCol = 0;
                    foreach (DataColumn c in t1.Columns)
                    {
                        iCol++;
                        newSheet.Cells[iRow + 1, iCol] = r[c.ColumnName];
                    }
                }

                return(newSheet);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 11
0
        public void AddSheet(InventorSheet inventorSheet)
        {
            var newSheet = new SheetCaptureDto(inventorSheet);

            newSheet.DrawingId = Id;

            Sheets.Add(newSheet);
        }
Exemplo n.º 12
0
        public void AddStyleSheet(string sheetPath)
        {
            var sheet = ConverterUtils.LoadResourceRequired <StyleSheet>(sheetPath);

            if (sheet != null)
            {
                Sheets.Add(sheet);
            }
        }
Exemplo n.º 13
0
 private void ReadWSheets()
 {
     WorkSheets.Clear();
     foreach (Sheet sheet in SDoc.WorkbookPart.Workbook.Descendants <Sheet>())
     {
         Sheets.Add(sheet);
         WorkSheets.Add(new ExWs(sheet, this));
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Add an existing sheet to the
 /// </summary>
 /// <param name="sheetName">workbookk´s sheet name</param>
 /// <returns></returns>
 public ExcelTestCaseDataReader AgregarHoja(string sheetName)
 {
     if (Sheets == null)
     {
         Sheets = new List <string>();
     }
     Sheets.Add(sheetName);
     return(this);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Add an existing sheet to the
        /// </summary>
        /// <param name="sheetName">workbookk´s sheet name</param>
        /// <returns></returns>
        public ExcelDataReader AddSheet(string sheet)
        {
            if (Sheets == null)
            {
                Sheets = new List <string>();
            }
            Sheets.Add(sheet);

            return(this);
        }
Exemplo n.º 16
0
        public void AddWorksheetToExcelWorkbook(string fullFilename, string worksheetName, GridView gridview)
        {
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Workbook  xlWorkbook = null;
            Sheets    xlSheets   = null;
            Worksheet xlNewSheet = null;

            try
            {
                xlApp = new Microsoft.Office.Interop.Excel.Application();

                //if (xlApp == null)
                //    return;

                // Uncomment the line below if you want to see what's happening in Excel
                // xlApp.Visible = true;

                xlWorkbook = xlApp.Workbooks.Open(fullFilename, 0, false, 5, "", "",
                                                  false, XlPlatform.xlWindows, "",
                                                  true, false, 0, true, false, false);

                xlSheets = xlWorkbook.Sheets as Sheets;

                // The first argument below inserts the new worksheet as the first one
                xlNewSheet      = (Worksheet)xlSheets.Add(xlSheets[1], Type.Missing, Type.Missing, Type.Missing);
                xlNewSheet.Name = worksheetName;


                xlNewSheet.Cells.Insert(0, 0);

                //---------------------
                int         i    = 0;
                GridViewRow row  = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
                TableCell   cell = new TableCell();
                cell.Text = String.Format(worksheetName, i);
                row.Cells.Add(cell);
                gridview.Controls[0].Controls.AddAt(i, row);

                //---------------------
                xlWorkbook.Save();
                xlWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);
                xlApp.Quit();
            }
            catch (Exception lkjlklkabb)
            {
            }
            finally
            {
                //Marshal.ReleaseComObject(xlNewSheet);
                //Marshal.ReleaseComObject(xlSheets);
                //Marshal.ReleaseComObject(xlWorkbook);
                //Marshal.ReleaseComObject(xlApp);
                xlApp = null;
            }
        }
        protected override IExternalExcelSheet AddOrGetInternal(string sheetName)
        {
            if (_obj == null)
            {
                return(null);
            }

            Worksheet ws     = null;
            bool      exists = false;

            if (!_write)
            {
                foreach (var ws1 in _worksheets.OfType <Worksheet>())
                {
                    try
                    {
                        if (ws1.Name.IgnoreCaseCompare(sheetName))
                        {
                            ws     = ws1;
                            exists = true;
                            break;
                        }
                    }
                    catch { }
                    finally
                    {
                        if (!exists)
                        {
                            Extensions.DisposeComObject(ws);
                        }
                    }
                }
            }

            if (ws == null)
            {
                ws      = _worksheets.Add();
                ws.Name = sheetName;
            }

            Range rows = ws.Rows;

            try
            {
                rows.Locked = false;
            }
            finally { Extensions.DisposeComObject(rows); }
            object missing = Type.Missing;

            ws.Protect(missing, missing, false, missing, missing, missing, missing, missing, missing,
                       missing, missing, missing, missing, missing, missing, missing);

            return(new MsOfficeExcelSheet(ws));
        }
Exemplo n.º 18
0
        public SFapp()
        {
            Sheet s = new Sheet()
            {
                Name = "Prova", Date = "11/22/3333", WeeklyFrequency = 5
            };

            s.AddRange(Day);
            Day.First().AddRange(Exercices);
            Sheets.Add(s);
        }
 private void InitPage()
 {
     for (int i = 0; i < MaxItems; i++)
     {
         Sheets.Add(new Sheet());
         if (i == 0 && Sheets[i] != null)
         {
             Sheets[i].IsCurrent = true;
         }
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Pulls all sheet data from the API.
        /// </summary>
        /// <returns></returns>
        public async Task Get()
        {
            var requestSheet         = Service.Spreadsheets.Get(ID);
            var requestSheetResponse = await requestSheet.ExecuteAsync();

            foreach (var sheet in requestSheetResponse.Sheets)
            {
                var s = new Sheet(this, sheet.Properties.SheetId.Value, sheet.Properties.Title);
                Sheets.Add(s);
            }
        }
        /// <summary>
        /// 初始化Fp。
        /// </summary>
        /// <param name="report">报表实体。</param>
        public void Init(Report report)
        {
            this.report = report;
            //获取报表样样式,判定是否可以编辑报表列。对于网格报表这样的样式,是可以编辑列的。对于交叉报表,是不能编辑列的。
            BaseReportStyle reportStyle = this.report.ReportStyle;

            canEditColumn = reportStyle.CanEditColumn();
            Sheets.Clear();
            Sheets.Add(sheetMain);
            InitFP();
        }
Exemplo n.º 22
0
        public void AddSheet(int w, int h, int src)
        {
            var tt = new RectangleSheet();

            tt.Name = "sheet" + (Sheets.Count + 1);
            Sheets.Add(tt);

            tt.source = src;
            tt.Height = h;
            tt.Width  = w;
            tt.Rebuild();
            ReorderSheets();
        }
Exemplo n.º 23
0
        public async Task <Sheet> AddSheet(string name)
        {
            var sheet = new Sheet(this, Sheets.Count, name);

            Sheets.Add(sheet);

            var batchRequest = new BatchUpdateSpreadsheetHelper(ID);

            batchRequest.Add((request) =>
            {
                // By default, a spreadsheet already has one sheet.
                // If there is more than one sheet, create a new one.
                // Otherwise, just update the title of the first one.
                if (Sheets.Count > 1)
                {
                    request.AddSheet = new AddSheetRequest()
                    {
                        Properties = new SheetProperties()
                        {
                            SheetId        = Sheets.Count - 1,
                            Title          = name,
                            GridProperties = new GridProperties()
                            {
                                ColumnCount = 1,
                                RowCount    = 1,
                            }
                        },
                    };
                }
                else
                {
                    request.UpdateSheetProperties = new UpdateSheetPropertiesRequest()
                    {
                        Properties = new SheetProperties()
                        {
                            Title          = name,
                            GridProperties = new GridProperties()
                            {
                                ColumnCount = 1,
                                RowCount    = 1,
                            }
                        },
                        Fields = "*",
                    };
                }
            });

            await batchRequest.ExecuteAsync(Service);

            return(sheet);
        }
        private void Exp()
        {
            FileInfo newFile = new FileInfo(@"\\192.168.12.33\oms-reports\ProductionRep.xlsx");



            Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
            //  ExcelApp.Visible = true;
            Workbook xlWorkbook = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

            DataTableCollection collection = ds.Tables;

            for (int i = collection.Count; i > 0; i--)
            {
                Sheets    xlSheets    = null;
                Worksheet xlWorksheet = null;
                //Create Excel Sheets
                xlSheets    = ExcelApp.Worksheets;
                xlWorksheet = (Worksheet)xlSheets.Add(xlSheets[1],
                                                      Type.Missing, Type.Missing, Type.Missing);

                System.Data.DataTable table = collection[i - 1];
                xlWorksheet.Name = table.TableName;

                for (int j = 1; j < table.Columns.Count + 1; j++)
                {
                    ExcelApp.Cells[1, j] = table.Columns[j - 1].ColumnName;
                }

                // Storing Each row and column value to excel sheet
                for (int k = 0; k < table.Rows.Count; k++)
                {
                    for (int l = 0; l < table.Columns.Count; l++)
                    {
                        ExcelApp.Cells[k + 2, l + 1] =
                            table.Rows[k].ItemArray[l].ToString();
                    }
                }
                // xlWorksheet.Cells[0, 0].Style.IsTextWrapped = true;
                ExcelApp.Columns.AutoFit();
            }
            ((Worksheet)ExcelApp.ActiveWorkbook.Sheets[ExcelApp.ActiveWorkbook.Sheets.Count]).Delete();
            //ExcelApp.Visible = true;
            // xlWorkbook.SaveCopyAs(@"C:\Niranjan.xlsx");
            // xlWorkbook.SaveCopyAs(@"D:\Export\ProductionRep.xlsx");
            xlWorkbook.SaveCopyAs(newFile);

            ExcelApp.DisplayAlerts = false;
            xlWorkbook.Close();
            ExcelApp.Quit();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates a workbook containing the specified number of sheets (not less than 1).
        /// </summary>
        /// <remarks>If <paramref name="numberOfSheets"/> is less than 1, the workbook will still
        /// contain one worksheet.</remarks>
        /// <param name="numberOfSheets">Number of sheets in the new workbook.</param>
        /// <returns>Workbook containing the specified number of sheets (not less than 1).</returns>
        public Workbook CreateWorkbook(int numberOfSheets)
        {
            Logger.Info("CreateWorkbook({0})", numberOfSheets);
            Workbook wb     = CreateWorkbook();
            Sheets   sheets = wb.Sheets;

            for (int i = 2; i <= numberOfSheets; i++)
            {
                sheets.Add(After: sheets[sheets.Count]);
            }
            ;
            Bovender.ComHelpers.ReleaseComObject(sheets);
            return(wb);
        }
Exemplo n.º 26
0
 private void GetSheets(ExcelMappingElement excelMappingElement)
 {
     foreach (var sheetElement in excelMappingElement.Sheets)
     {
         Sheets.Add(new SheetConfig
         {
             NoSheet            = sheetElement.NoSheet,
             SheetName          = sheetElement.SheetName,
             RowNumberStartData = sheetElement.RowNumberStartData,
             RowNumberStopData  = string.IsNullOrEmpty(sheetElement.RowNumberStopData) ? -1 : int.Parse(sheetElement.RowNumberStopData),
             Map = sheetElement.Map
         });
     }
 }
Exemplo n.º 27
0
        internal XLSWorkbook(string path, ExcelSheetReadConfig config) : base(path)
        {
            string tmpFile = Path.GetTempFileName();

            File.Copy(path, tmpFile, true);

            rawWorkbook = new XSSFWorkbook(tmpFile);

            for (int i = 0; i < rawWorkbook.NumberOfSheets; i++)
            {
                var srcSheet = rawWorkbook.GetSheetAt(i);
                Sheets.Add(srcSheet.SheetName, new XLSExcelSheet(srcSheet, config));
            }
        }
Exemplo n.º 28
0
        public void ClearWorkBook()
        {
            Sheets sheets = Application.ActiveWorkbook.Sheets;

            sheets.Add().Name = "29185D52CD5441A";
            foreach (dynamic sheet in sheets)
            {
                if (sheet.Name != "29185D52CD5441A")
                {
                    sheets[sheet.Name].Delete();
                }
            }
            sheets[1].Name = "EmptySheet";
        }
Exemplo n.º 29
0
        public Calculator(string path)
        {
            this.path = path;

            using (var file = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                // read sheets
                Workbook   = new HSSFWorkbook(file);
                SheetCount = Workbook.NumberOfSheets;
                for (int i = 0; i < SheetCount; i++)
                {
                    Sheets.Add(Workbook.GetSheetAt(i));
                }
            }
        }
Exemplo n.º 30
0
        private void LoadBFN(EndianBinaryReader reader)
        {
            // Get the block count
            reader.Skip(12);
            int block_count = reader.ReadInt32();

            reader.Skip(16);

            // There can be multiple INF1 blocks in a file, but only the last one is used.
            do
            {
                block_count--;
                reader.Skip(8);

                Encoding        = (CodepointEncoding)reader.ReadInt16();
                Ascent          = reader.ReadInt16();
                Descent         = reader.ReadInt16();
                CharacterWidth  = reader.ReadInt16();
                Leading         = reader.ReadInt16();
                ReplacementCode = reader.ReadInt16();

                reader.Skip(12);
            } while (reader.PeekReadInt32() == 0x494E4631); // INF1

            for (int i = 0; i < block_count; i++)
            {
                int fourcc = reader.ReadInt32();

                switch (fourcc)
                {
                // GLY1
                case 0x474C5931:
                    Sheets.Add(new Sheet(reader));
                    break;

                // MAP1
                case 0x4D415031:
                    GlyphBlocks.Add(new GlyphBlock(reader));
                    break;

                // WID1
                case 0x57494431:
                    LoadWidths(reader);
                    break;
                }
            }
        }