私は正常に動作するコードを書いています.このコードには、画像とテキストをExcelセルに転送することが含まれており、エラーが発生するクライアントコンピューターの1つで正常に動作します:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
データテーブルを Excel にエクスポートするコード:
string ImageFolderPath = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Images\\";
SaveFileDialog saveFileDialog1=new SaveFileDialog();
saveFileDialog1.Filter = "Excel (*.xls)|*.xls";
// saveFileDialog1.Title = "Select Empty Excel Sheet";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (!saveFileDialog1.FileName.Equals(String.Empty))
{
FileInfo f = new FileInfo(saveFileDialog1.FileName);
if (f.Extension.Equals(".xls") || f.Extension.Equals(".xlsx"))
{
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
xlWorkSheet.Cells[3, 1] = "SKU";
xlWorkSheet.Cells[3, 2] = "EAN IPC";
xlWorkSheet.Cells[3, 3] = "ASIN";
xlWorkSheet.Cells[3, 4] = "CONDITION";
xlWorkSheet.Cells[3, 5] = "PRICE";
xlWorkSheet.Cells[3, 6] = "PRODUCT TITLE";
xlWorkSheet.Cells[3, 7] = "STATUS";
xlWorkSheet.Cells[3, 8] = "PRODUCT IMAGE";
xlWorkSheet.Cells[3, 9] = "PRODUCT URL";
xlWorkSheet.Cells[3, 10] = "IMAGE NAME";
xlWorkSheet.Cells[2, 1] = "Accept Value :";
xlWorkSheet.Cells[2, 2] = textBox1.Text;
xlWorkSheet.Cells[2, 4] = "Location :";
xlWorkSheet.Cells[2, 5] = "Amazon.co.uk";
for (i = 0; i <= resultSheet.Rows.Count - 1; i++)
{
for (j = 0; j <= resultSheet.Columns.Count - 1; j++)
{
if (j == 7)
{
string imagString = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Images\\";
imagString = imagString + resultSheet.Rows[i][j+2].ToString();
Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[i + 5, j + 1];
float Left = (float)((double)oRange.Left);
float Top = (float)((double)oRange.Top);
const float ImageSize = 32;
xlWorkSheet.Shapes.AddPicture(imagString, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
oRange.RowHeight = ImageSize + 2;
}
else
{
xlWorkSheet.Cells[i + 5, j + 1] = resultSheet.Rows[i][j].ToString();
}
}
}
xlWorkBook.SaveAs(saveFileDialog1.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.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 , you can find the file " + saveFileDialog1.FileName);
}
else
{
MessageBox.Show("Invalid file type");
}
}
else
{
MessageBox.Show("You did pick a location " +
"to save file to");
}
}
クライアントはExcel 2002を使用しているため、どうすればよいかわかりません!