示例#1
0
        /// <summary>
        /// Creates a row of cells containing log information and appends under the lowest cells containing data. Expands the tab and cells to fit the data.
        /// </summary>
        /// <param name="spreadsheetId">The id of the sheets doc</param>
        /// <param name="tabName">The name of the tab to write to</param>
        /// <param name="timeStr">String containing information to write</param>
        /// <param name="description">String containing information to write</param>
        /// <returns></returns>
        public static bool WriteTimeNowToCell(string spreadsheetId, string tabName, string timeStr, string description)
        {
            if (m_shouldRun == false)
            {
                return(false);
            }

            // TODO: properly validate spreadsheet id
            if (spreadsheetId.Length == 0)
            {
                return(false);
            }

            SheetsLogEntry entrymaker = new SheetsLogEntry();

            List <RowData> rowDataList = new List <RowData>();

            rowDataList.Add(entrymaker.addEntry(timeStr, description));

            Request appendCells = requestAppendCells(spreadsheetId, tabName, rowDataList);
            Request autoSize    = requestDimensionAutoSize(spreadsheetId, tabName, 0);

            BatchUpdateSpreadsheetRequest batchRequest = new BatchUpdateSpreadsheetRequest();

            batchRequest.Requests = new List <Request>();
            batchRequest.Requests.Add(autoSize);
            batchRequest.Requests.Add(appendCells);

            return(ExecuteBatchRequest(batchRequest, spreadsheetId));
        }
示例#2
0
        private void googleSheetsInterfaceSetup()
        {
            // not run if the target isn't set up within the program
            if (m_foundGoogleSheetAndTab == false)
            {
                return;
            }

            PrefsData.PrefLogIndex index = m_userPrefs.getActiveSheet();

            string googleSheetsId = m_userPrefs.getLogGoogleId(index);
            string tabName        = m_userPrefs.getProjectName(index);

            if (googleSheetsId == "" || tabName == "")
            {
                DialogMessage message = new DialogMessage("Information", "A Google Sheets id and tab name must be set in order to use google sheets interface.\nInteraction with google sheet will not function.");
                message.ShowDialog();
                return;
            }

            // check wth google sheets to see if the tab needs to be created
            if (!TCOSheetsInterface.tabExists(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index)))
            {
                System.Drawing.Size size = new System.Drawing.Size(5, 2);
                if (!TCOSheetsInterface.createTab(m_userPrefs.getLogGoogleId(index), m_userPrefs.getProjectName(index), size, 1))
                {
                    Console.WriteLine("Create new tab [" + m_userPrefs.getProjectName(index) + "] failed");
                }

                // create the header bar in the created tab
                SheetsLogEntry entryMaker = new SheetsLogEntry();
                List <Google.Apis.Sheets.v4.Data.RowData> rows = entryMaker.createTitleBar();
                TCOSheetsInterface.updateCells(
                    m_userPrefs.getLogGoogleId(index),
                    m_userPrefs.getProjectName(index),
                    "A1", "E2", rows);
            }
        }