Pessoal preciso de ajuda.
Tenho o seguinte Data DataGridView e esta a planilha que se encontra já pronta, apenas quero inserir os campos das colunas [Producao], [DSR] e [Feriado] do DGV na planilha abaixo e a partir da linha 8
e nas células B8, F8 E J8 desta planilha para cada funcionário com seu devido valor
Meu código é este, mas não está dando certo.
está repetindo o mesmo valor para todos os funcionários da planilha.
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application XcelApp;
Microsoft.Office.Interop.Excel.Workbooks myExcelWorkbooks;
Microsoft.Office.Interop.Excel.Workbook myExcelWorkbook;
object misValue = System.Reflection.Missing.Value;
XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
XcelApp.Visible = true;
myExcelWorkbooks = XcelApp.Workbooks;
String fileName = @"D:\DocumentosGeral_Fazendas\PontosRural\PlanilhaFatos - Todos Registros 31-05-2015.xls"; //set this to your file you want
myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, misValue, misValue,
misValue, misValue, misValue, misValue, misValue,
misValue, misValue, misValue, misValue, misValue, misValue);
Microsoft.Office.Interop.Excel.Worksheet myExcelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)myExcelWorkbook.ActiveSheet;
myExcelWorksheet.Unprotect("");
//this puts the formula in Cell A2 or text depending whats in it in the string.
// String cellFormulaAsString = myExcelWorksheet.get_Range("A2", misValue).Formula.ToString();
//this changes the cell value in C2 to "New Value"
string QtdLinhas = dgvResultados.Rows.Count.ToString();
int qtdLinhas = 7 + int.Parse(QtdLinhas);
for (int i = 0; i < qtdLinhas; i++)
{
myExcelWorksheet.get_Range("B8", "B" + qtdLinhas.ToString()).Value2 = dgvResultados.Rows[i].Cells[2].Value;
myExcelWorksheet.get_Range("F8", "F" + qtdLinhas.ToString()).Value2 = dgvResultados.Rows[i].Cells[6].Value;
}
}
Antecipo agradecimentos.
Airton Barros
Airton Barros