PDA

View Full Version : مشکل در کار با اکسل



corona
جمعه 12 فروردین 1390, 16:56 عصر
با سلام و تبریک سال نو به همه برنامه نویسان و دوستان عزیز.
توی کد زیر وقتی به خطی که workbook رو new می کنم می رسه خطای

Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154
رو میده که هر چی تلاش کردم بفهمم مشکل از چیه نتیجه نگرفتم. لطفا اگه کسی راه حلی داره بگه ممنون میشم.



private Application newApp = null;
private Workbook workBook = null;
private Worksheet sheet1 = null;
private Range newRange = null;

public Form1()
{
InitializeComponent();
newApp = new Application();
workBook = new Workbook();
workBook = newApp.Workbooks.Open("c:\\Book1.xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

sheet1 = (Worksheet)workBook.Worksheets.get_Item(1);
dataGridView1.DataSource = sheet1;

}

corona
جمعه 19 فروردین 1390, 09:18 صبح
دوستان عزیز آقایان مدیر واقعا یعنی هیج کس تا حالا به این مشکل برخورد نکرده ؟

ad.davachi
دوشنبه 17 بهمن 1390, 10:40 صبح
سلام منم این مشکل رو دارم آیا تونستید حلش کنید؟

majid.gymnast
دوشنبه 17 بهمن 1390, 11:12 صبح
ارسال اطلاعات به اکسل :من این کلاسو برای تبدیل دیتا گریدویو به اکسل نوشتم هرجا TheGrid دیدین یعنی دیتاگریدویو :
using (System.IO.StreamWriter fs = new System.IO.StreamWriter(آدرس فایل, false))
{
fs.WriteLine("<?xml version=\"1.0\"?>");
fs.WriteLine("<?mso-application progid=\"Excel.Sheet\"?>");
fs.WriteLine("<ss:Workbook xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");
fs.WriteLine(" <ss:Styles>");
fs.WriteLine(" <ss:Style ss:ID=\"1\">");
fs.WriteLine(" <ss:Font ss:Bold=\"1\"/>");
fs.WriteLine(" </ss:Style>");
fs.WriteLine(" </ss:Styles>");
fs.WriteLine(" <ss:Worksheet ss:Name=\"Sheet1\">");
fs.WriteLine(" <ss:Table>");
for (int x = 0; x <= TheGrid.Columns.Count - 1; x++)
{
if (TheGrid.Columns[x].Visible)
{
fs.WriteLine(" <ss:Column ss:Width=\"{0}\"/>", TheGrid.Columns[x].Width);
}
}
fs.WriteLine(" <ss:Row ss:StyleID=\"1\">");
for (int i = 0; i <= TheGrid.Columns.Count - 1; i++)
{
if (TheGrid.Columns[i].Visible)
{
fs.WriteLine(" <ss:Cell>");
fs.WriteLine(string.Format(" <ss:Data ss:Type=\"String\">{0}</ss:Data>", TheGrid.Columns[i].HeaderText));
fs.WriteLine(" </ss:Cell>");
}
}
fs.WriteLine(" </ss:Row>");
for (int intRow = 0; intRow <= TheGrid.RowCount - 1; intRow++)
{
if (!TheGrid.Rows[intRow].Selected) continue;

fs.WriteLine(string.Format(" <ss:Row ss:Height =\"{0}\">", TheGrid.Rows[intRow].Height));
for (int intCol = 0; intCol <= TheGrid.Columns.Count - 1; intCol++)
{
if (TheGrid[intCol, intRow].Visible)
{
fs.WriteLine(" <ss:Cell>");
fs.WriteLine(string.Format(" <ss:Data ss:Type=\"String\">{0}</ss:Data>", (TheGrid.Rows[intRow].Cells[intCol].Value != null) ? TheGrid.Rows[intRow].Cells[intCol].Value.ToString() : string.Empty));
fs.WriteLine(" </ss:Cell>");
}
}
fs.WriteLine(" </ss:Row>");
}
fs.WriteLine(" </ss:Table>");
fs.WriteLine(" </ss:Worksheet>");
fs.WriteLine("</ss:Workbook>");
}
MessageBox.Show("عملیات با موفقیت انجام شد");