0
我有幾個表中的sql,我想將它們導出爲PDF文件後,我單擊表格按鈕 沒有人知道我該怎麼做?從Sql Server導出到PDF文件使用c#
我有這樣的代碼,當我從SQL表導出到Excel:
protected void insertBTN(object sender, EventArgs e)
{
string conString = @"Data Source =XXXX; Initial Catalog=XXXX; Persist Security Info=True;User ID=XXXX; Password=XXXX";SqlConnection sqlCon = new SqlConnection(conString);
sqlCon.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * from InjuryScenario", sqlCon);
System.Data.DataTable dtMainSQLData = new System.Data.DataTable();
da.Fill(dtMainSQLData);
DataColumnCollection dcCollection = dtMainSQLData.Columns;
// Export Data into EXCEL Sheet
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
ExcelApp.Application.Workbooks.Add(Type.Missing);
// ExcelApp.Cells.CopyFromRecordset(objRS);
for (int i = 1; i < dtMainSQLData.Rows.Count + 2; i++)
{
for (int j = 1; j < dtMainSQLData.Columns.Count + 1; j++)
{
if (i == 1)
{
ExcelApp.Cells[i, j] = dcCollection[j - 1].ToString();
}
else
ExcelApp.Cells[i, j] = dtMainSQLData.Rows[i - 2][j - 1].ToString();
}
}
ExcelApp.ActiveWorkbook.SaveCopyAs("C:\\Users\\Mor Shivek\\Desktop\\test.xls");
ExcelApp.ActiveWorkbook.Saved = true;
ExcelApp.Quit();
}
我想有救選項PDF格式的文件 – user3082812
那麼就這樣吧!? http://stackoverflow.com/questions/13233359/saving-file-as-pdf-by-using-microsoft-office-interop-excel – silent
它不工作,所以... – user3082812