Beispiel #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();
        }
Beispiel #2
0
        private GoogleCell ReadCell(GoogleCellCoordinate coordinate)
        {
            var range   = $"{SheetTab}!" + coordinate.Column + coordinate.Row;
            var request = Service.Spreadsheets.Values.Get(SheetUrl, range);

            GoogleCell cell = new GoogleCell();

            cell.Coordinate = coordinate;
            cell.Origin     = GetCurrentOrigin();

            var response = request.Execute();
            var values   = response.Values;

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    cell.OriginalContent = row[0];
                    cell.Content         = cell.OriginalContent;
                    return(cell);
                }
            }

            //- Error, not found
            if (!IgnoreNull)
            {
                Console.WriteLine("No data was found in: " + range);
                return(null);
            }
            else
            {
                cell.OriginalContent = "";
                cell.Content         = cell.OriginalContent;
                return(cell);
            }
        }
Beispiel #3
0
 public void WriteCell(string content, GoogleCellCoordinate coordinate)
 {
     WriteCell(content, coordinate.Column + coordinate.Row);
 }
Beispiel #4
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);
        }
Beispiel #5
0
 //- Read (Single)
 public GoogleCell ReadCell(string cell)
 {
     return(ReadCell(GoogleCellCoordinate.FromCell(cell)));
 }