コード例 #1
0
ファイル: SpreadsheetJob.cs プロジェクト: walkure/KCBr
        /// <summary>
        /// ワークシートを追加する
        /// </summary>
        /// <param name="name">ワークシート名</param>
        /// <param name="columns">追加するカラム数</param>
        /// <returns>作成されたワークシート</returns>
        public static WorksheetEntry CreateWorksheet(this WorksheetFeed feed,
                                                     string name, int columns)
        {
            //現状、どっちでも動く
            WorksheetEntry worksheet = (WorksheetEntry)feed.CreateFeedEntry();

            //            WorksheetEntry worksheet = new WorksheetEntry();
            worksheet.Title.Text = name;

            ///columnsは規定数ないとCellFeed.Insertで死ぬ
            worksheet.Cols = (uint)columns;

            //rowsは勝手にListFeed.Insertで増えてく
            worksheet.Rows = 1;

            //追加する。追加された結果Entryを使って次の処理を行う
            return(feed.Insert(worksheet));
        }
コード例 #2
0
        public void InsertWorksheetTest()
        {
            Tracing.TraceMsg("Entering InsertWorksheetTest");

            SpreadsheetQuery    query   = new SpreadsheetQuery();
            SpreadsheetsService service = new SpreadsheetsService(this.ApplicationName);

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }
            service.RequestFactory = this.factory;

            SpreadsheetFeed feed = service.Query(query);

            Assert.IsTrue(feed != null, "Need to have a spreadsheet feed");
            Assert.IsTrue(feed.Entries != null && feed.Entries.Count > 0, "Need to have one spreadsheet in there");

            SpreadsheetEntry entry = feed.Entries[0] as SpreadsheetEntry;

            string wUri = entry.WorksheetsLink;

            Assert.IsTrue(wUri != null, "Need to have a worksheet feed in the spreadsheet entry");

            WorksheetFeed sheets = entry.Worksheets;


            // kill all but the default before we start
            foreach (WorksheetEntry w in sheets.Entries)
            {
                if (w.Title.Text != "DefaultSheet")
                {
                    w.Delete();
                }
            }

            WorksheetEntry defEntry = sheets.Entries[0] as WorksheetEntry;

            Assert.IsTrue(defEntry != null, "There should be one default entry in this account/sheet");
            Assert.IsTrue(defEntry.Title.Text == "DefaultSheet", "it should be the default sheet");
            CellFeed defCells = defEntry.QueryCellFeed();

            Assert.IsTrue(defCells != null, "There should be a cell feed for the worksheet");


            CellEntry header = null;

            foreach (CellEntry cell in defCells.Entries)
            {
                if (cell.Title.Text == "A1")
                {
                    cell.Cell.InputValue = string.Empty;
                    cell.Update();
                    header = cell;
                }
            }



            if (header != null)
            {
                header.InputValue = "HeaderA";
                header.Update();
            }


            WorksheetEntry newEntry = sheets.Insert(new WorksheetEntry(10, 20, "New Worksheet"));

            Assert.IsTrue(newEntry.ColCount.Count == 20, "Column count should be equal 20");
            Assert.IsTrue(newEntry.RowCount.Count == 10, "Row count should be equal 10");
            Assert.IsTrue(newEntry.Title.Text == "New Worksheet", "Titles should be identical");

            CellFeed cells = newEntry.QueryCellFeed(ReturnEmptyCells.yes);

            Assert.IsTrue(cells != null, "There should be a cell feed for the new worksheet");
            Assert.IsTrue(cells.Entries.Count == 200, "There should be 200 cells");
            for (uint row = 1; row <= 10; row++)
            {
                for (uint col = 1; col <= 20; col++)
                {
                    cells[row, col].InputValue = "R" + row + "C" + col;
                }
            }
            cells.Publish();

            // try to update just one cell
            cells[1, 1].InputValue = string.Empty;
            cells[1, 1].Update();

            for (uint row = 1; row <= 10; row++)
            {
                for (uint col = 1; col <= 20; col++)
                {
                    cells[row, col].InputValue = string.Empty;
                }
            }
            cells.Publish();
            // cleanup the new worksheet at the end
            newEntry.Delete();
        }