엑셀 파일에 쓰고 저장하는이 기능이 있습니다. 이 존재하고 존재하는 경우 추가 작업을 수행하는 경우이 특정 블록은 파일을 확인한다기존 엑셀 파일에 추가하기
private void button8_Click(object sender, EventArgs e)//creates excel file and writes data to it
{
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("Excel is not properly installed!!");
return;
}
if (System.IO.File.Exists("cross_check.xls"))
{
}
else
{
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
IndexProp += 1;
xlWorkSheet.Cells[IndexProp, 1] = comboBox2.Text;
xlWorkSheet.Cells[IndexProp, 2] = textBox5.Text;
xlWorkSheet.Cells[IndexProp, 3] = textBox2.Text;
xlWorkSheet.Cells[IndexProp, 4] = comboBox3.Text;
xlWorkSheet.Cells[IndexProp, 5] = textBox3.Text;
xlWorkSheet.Cells[IndexProp, 6] = comboBox1.Text;
xlWorkBook.SaveAs(@"cross_check.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
MessageBox.Show("Excel file created succcessfully");
}
}
}
: 내가 지금하고 싶은 것은 같은 기존의 엑셀 file.This에 추가 것은 기능입니다. 어떻게해야합니까? 당신은 파일을 열고 자하는 것이다
if (System.IO.File.Exists("cross_check.xls"))
{
}
Excel 기능을 사용하지 않는 한 Excel에서 쉽게 사용할 수있는 .CSV 파일을 만들고 추가하는 것이 훨씬 쉽습니다. Interop이 어려울 것 같습니다. 특히 프로그램이 다른 PC에서 실행되는 경우 특히 그렇습니다. Excel 기능이 있으면 다음 작업을 수행하기 위해 Excel에서 VBA를 사용해보십시오. Interop이 나의 마지막 선택 일 것입니다. – rheitzman
@rheitzman 문제는이 .csv 파일에 잠시 후에 문제가 될 수 있으므로 데이터 격자에이 Excel 파일을로드 할 계획입니다. – Jevon