نوشته شده توسط
hosseinbarnamenevis
یه سوال؟ از کامپاننت خاصی استفاده میکنید؟
برق رفت حالا توی این هیروویری
از 4تا dll که شاید مال اونا باشه استفاده می کنم:
1- microsoft.office.introp.word
2- microsoft.office.introp.excel
که برای اینه که فایل ورد یا اکسلی که از بانک فراخوانی می کنه رو به pdf تبدیل کنم.
3- acropdflib
4- axacropdflib
که برای اینه که اون pdf رو توی کنترل axacropdf که برای برنامه acrobat reader هست نمایش بدم.
تابعی که باهاش اطلاعات رو ازبانک می خونم:
private void GetbufferTextDakheliLettere()
{
try
{
SqlConnection con =
new SqlConnection(clsForms.ConnectionString);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = con;
da.SelectCommand.CommandType = CommandType.Text;
da.SelectCommand.CommandText = @"SELECT FileFile, FormateFile
FROM tblErsali
WHERE ID = (SELECT LetterID
FROM tblDaryafti
WHERE ID = " + Program.LetterIdDaryafti + ")";
con.Open();
da.Fill(ds, "Word_Get");
con.Close();
buffer = (byte[])ds.Tables["Word_Get"].Rows[0]["FileFile"];
FormateFile = ds.Tables["Word_Get"].Rows[0]["FormateFile"].ToString();
}
catch (Exception)
{
}
}
و با این به pdf تبدیل و توی کنترل مربوطه به آکروبات ریدر نشون می دم.
GetbufferTextDakheliLettere();
if (FormateFile == ".docx" || FormateFile == ".doc")
{
try
{
string TempFile = Path.GetTempFileName();
File.WriteAllBytes(TempFile, buffer);
File.Move(TempFile, TempFile + FormateFile);
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(TempFile + FormateFile);
wordDocument.ExportAsFixedFormat(TempFile + ".pdf", WdExportFormat.wdExportFormatPDF);
axAcroPDF1.src = TempFile + ".pdf";
}
catch (Exception)
{
}
}
else if (FormateFile == ".xlsx" || FormateFile == ".xls")
{
try
{
string TempFile = Path.GetTempFileName();
File.WriteAllBytes(TempFile, buffer);
File.Move(TempFile, TempFile + FormateFile);
ExportWorkbookToPdf(TempFile + FormateFile, @"C:\bbb.xlsx");
axAcroPDF1.src = @"C:\bbb.xlsx" + ".pdf";
}
catch (Exception)
{
}
}
نوشته شده توسط
kavayo
توی گوگل که سرچ میکنی چندین راه حل برای این مشکل انجام شده یکی اش رو امتحان کن .
توی گوگل سرچ کردم و چیزی سردرنیاوردم. توی پست 6 هستش.