The original program used Word and Excel to do some export data and print operations, but running for some time found that there are always some users of the computer installed on the office some problems, but also need to reinstall the adjustment caused some additional maintenance work.
This is done by simply trying to use fastreport instead of office, generating some of the data that needs to be exported as a report, and saving it as an Excel format, so you can reduce unnecessary hassles.
In the program to the connection information from the report, to avoid the report file is not secure, in addition, this connection information can be done separately in the configuration file.
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.text;using system.windows.forms;using system.data.sqlclient;namespace test fastreport{public partial class Form1:form {private DataSet data; Public Form1 () {InitializeComponent (); private void Button1_Click (object sender, EventArgs e) {string constr = "server= ' 127.0.0.1 '; in Itial Catalog=waimaojinkou; uid= ' sa '; Pwd= ' 12345 '; Max Pool size=512; "; try {SqlConnection con = new SqlConnection (CONSTR); Con. Open (); SqlCommand sqlcmd = new SqlCommand (); sqlcmd. Connection = con; Sqlcmd.commandtext = @ "SELECT * FROM [Event]"; SqlDataAdapter SDA = new SqlDataAdapter (sqlcmd); data = new DataSet (); Sda. Fill (data); Con. Close (); Sda. DisPose (); } catch (Exception err) {MessageBox.Show (err. StackTrace); try {fastreport.report report = new Fastreport.report (); string filename = Application.startuppath + @ "\frxreport\qualityevent.frx"; string filename = @ "D:\qualityEvent.frx"; Report. Load (filename); Report. Registerdata (data); Report. Getdatasource (data. Tables[0]. TableName). Enabled = true; Report. Show (); } catch (Exception err) {MessageBox.Show (err. Message); } } }}
Tried a few times, only used. Net4.0, Fastreport will be recognized, so the development of the project also needs to be re-set, reinstall. NET4.0 Framework Package.