예제 #1
0
        //- Append (Multiple)
        public void Append(GoogleCell[] cells)
        {
            if (cells == null || cells.Length == 0)
            {
                return;
            }
            GoogleCell           left = cells[0];
            GoogleCellCoordinate cor  = new GoogleCellCoordinate();

            cor.Column = GoogleCellCoordinate.ToString(GoogleCellCoordinate.ToInt32(left.Coordinate.Column) + cells.Length);

            string     range      = $"{SheetTab}!" + left.Coordinate.Column + ":" + cor.Column;
            ValueRange valueRange = new ValueRange();

            List <object> objectList = new List <object>();

            foreach (GoogleCell cell in cells)
            {
                objectList.Add(cell.Content);
            }

            valueRange.Values = new List <IList <object> > {
                objectList
            };

            var updateRequest = Service.Spreadsheets.Values.Append(valueRange, SheetUrl, range);

            updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
            var updateResponse = updateRequest.Execute();
        }
예제 #2
0
        //- Read (Complete Tab)
        public List <GoogleCell[]> ReadFull()
        {
            string range   = $"{SheetTab}";
            var    request = Service.Spreadsheets.Values.Get(SheetUrl, range);

            GoogleCellCoordinate first = new GoogleCellCoordinate()
            {
                Column = "A", Row = 1
            };

            var response = request.Execute();
            IList <IList <object> > values = response.Values;

            List <GoogleCell[]> local = new List <GoogleCell[]>();

            int column_max = 0;

            if (CompleteFill && values != null && values.Count > 0)
            {
                int biggest = 0;
                for (int row = 0; row < values.Count; row++)
                {
                    if (values[row].Count > biggest)
                    {
                        biggest = values[row].Count;
                    }
                }
                column_max = biggest;
            }

            if (values != null && values.Count > 0)
            {
                for (int row = 0; row < values.Count; row++)
                {
                    int intern_length = values[row].Count;
                    if (CompleteFill)
                    {
                        intern_length = column_max;
                    }
                    GoogleCell[] complete_row = new GoogleCell[intern_length];
                    for (int column = 0; column < values[row].Count; column++)
                    {
                        GoogleCell cell = new GoogleCell();
                        cell.Content    = values[row][column];
                        cell.Coordinate = new GoogleCellCoordinate()
                        {
                            Column = GoogleCellCoordinate.ToString(GoogleCellCoordinate.ToInt32(first.Column) + column),
                            Row    = first.Row + row
                        };
                        cell.Origin = GetCurrentOrigin();
                        if (cell.Content != null && cell.Content.ToString() != "")
                        {
                            complete_row[column] = cell;
                        }
                    }
                    local.Add(complete_row);
                }
            }
            if (local.Count == 0)
            {
                Console.WriteLine("No data was found: " + range);
            }
            return(local);
        }