private static void GerarTabelaSavingsSheet(int indice) { DateTime mes = DateTime.Now.AddMonths(indice); List <IList <object> > dados = new List <IList <object> >(); string saldo_mes; if (indice == 0) { saldo_mes = ConsolidadoService.GetValue("savings").Replace(".", ","); } else { saldo_mes = "=" + colunaValorAnterior + linha_total_savings; } var dt = mes.ToString("MMMM", CultureInfo.CreateSpecificCulture("pt-BR")); dados.Add(new List <object>() { dt.First().ToString().ToUpper() + dt.Substring(1), saldo_mes }); char coluna_nome = GetColumn(indice); char coluna_valor = (char)(((int)coluna_nome) + 1); colunaValorAnterior = coluna_valor; dados.Add(new List <object>() { "Save", "=" + coluna_valor + linha_save }); dados.Add(new List <object>() { "Total", "=SUM(" + coluna_valor + linha_savings + ":" + coluna_valor + limite_savings + ")" }); string range = "!" + coluna_nome + linha_savings + ":" + coluna_valor + linha_total_savings; ValueRange valueRange = new ValueRange(); valueRange.Values = dados; SpreadsheetsResource.ValuesResource.UpdateRequest updateRequest = sheetsService.Spreadsheets.Values.Update(valueRange, idPlanilha, range); updateRequest.ValueInputOption = valueInputOption; UpdateValuesResponse resposta = updateRequest.Execute(); }
private static void GerarTabelaMesSheet(int indice) { DateTime mes = DateTime.Now.AddMonths(indice); List <IList <object> > dados = new List <IList <object> >(); var movimentacoes = ContasService.GetMovimentacoes(mes).Where(m => m.Status != "pago").ToList(); string saldo_mes; Double saldo_parcial; if (indice == 0) { saldo_mes = ConsolidadoService.GetValoresConsolidados().ToString("F"); } else { saldo_mes = "=SUM(" + Double.Parse(ConsolidadoService.GetValue("salario")) + "+" + colunaValorAnterior + linha_sobra + ")"; } saldo_parcial = sobra + Double.Parse(ConsolidadoService.GetValue("salario")); var dt = mes.ToString("MMMM", CultureInfo.CreateSpecificCulture("pt-BR")); dados.Add(new List <object>() { dt.First().ToString().ToUpper() + dt.Substring(1), saldo_mes }); for (int i = 0; i < maximoMovimentacoes; i++) { if (movimentacoes.ElementAtOrDefault(i) != null) { dados.Add(new List <object>() { "'" + movimentacoes[i].Nome + ContasService.GetSiglaCartao(movimentacoes[i].IdCartao), movimentacoes[i].Valor.ToString("F") }); } else { dados.Add(new List <object>() { null }); } } var save = (Double)ContasService.GetSaveMes(mes); dados.Add(new List <object>() { "Save", save.ToString("F") }); char coluna = GetColumn(indice); char proxima = (char)(((int)coluna) + 1); colunaValorAnterior = proxima; dados.Add(new List <object>() { "Total", "=SUM(" + proxima + "3:" + proxima + limite + ")" }); var gastos = (Double)movimentacoes.Where(m => m.Tipo == "gasto" && m.Status != "pago").Sum(m => m.Valor); sobra = saldo_parcial - gastos - save; // dados.Add(new List<object>() { "Sobra", "="+proxima+"2-"+proxima+linha_total+"-"+proxima+linha_save }); string range = "!" + coluna + "2:" + proxima + dados.Count + 1; ValueRange valueRange = new ValueRange(); valueRange.Values = dados; SpreadsheetsResource.ValuesResource.UpdateRequest updateRequest = sheetsService.Spreadsheets.Values.Update(valueRange, idPlanilha, range); updateRequest.ValueInputOption = valueInputOption; UpdateValuesResponse resposta = updateRequest.Execute(); }