To open new Excel sheet from Silverlight - silverlight

I creating Silverlight App, while exporting grid into excel, I need to open a new Excel sheet but I was not able to open a new Excel within silverlight. I am using Telerik controls, in their examples , they are saving a new excel and then exoporting data. But my client need not want the save operation performed before exporting the Grid data.
The flow should be like the one below:
1. Open new excel (Excel should be in front of the screen)
2. export data
3. Saving the excel is enduser 's choice .
The end user may or may not save the Excel sheet according to their need.
Can any one help me to solve this problem.
Thank You

private void button8_Click(object sender, RoutedEventArgs e)
{
dynamic excelApp;
excelApp = AutomationFactory.CreateObject("Excel.Application");
excelApp.Visible = true;
dynamic workbook = excelApp.workbooks;
workbook.Add();
dynamic sheet = excelApp.ActiveSheet;
dynamic cell = null;
int index = 1;
foreach (unite emp in dataGrid1.ItemsSource)
{
cell = sheet.Cells[index, 1];
cell.Value = emp.unite_description;
cell = sheet.Cells[index, 2];
//cell.Value = emp.EmployeeId;
//cell = sheet.Cells[index, 3];
//cell.Value = emp.Department;
index++;
}
}
This is what I found when I had the same problem as you and it's working as you asked. (Declaring variables as dynamic is probably not necessary)

Use excellite library. it is an appropriate free tool for reading and writing Excel files.
you can find it hear: http://excellite.codeplex.com/

Related

Transfer SQL Objects using ssis according to given name

Suppose, We have two databases , db_1 and db_2.
There are a table named 'T1' in db_1, now,I need a package in SSIS which will ask for names sql objects.If I choose 'T1',the data will be transfered to db_2.
I dont know if it is possible.
Generally SSIS is not meant to be used in an Interactive mode. Any user input is either introduced as a config setting or environment variable or as values in some other table.
Alternately, you can also prompt for and capture input values outside of the SSIS Package and then execute the SSIS Package, in C# or ASP.Net or any other interactive platform.
That said, if you must prompt for input and use it, the way to do it is by instantiating and displaying a Form in a Script Component.
Create a variable at the appropriate scope called tableName in the package. Then use the code below (modify it as needed) to set the tableName variable's value to whatever the user enters. Finally, use the same tableName variable in your control flow to copy the data from.
System.Windows.Forms.Form frm = new Form();
TextBox = new TextBox();
Button submitButton = new Button();
public void Main()
{
submitButton.Text = "Enter source table name";
submitButton.Width = 300;
submitButton.Height = 80;
submitButton.Click += new EventHandler(submitButton_Click);
tableNameTextBox.Name = "Input";
frm.Controls.Add(tableNameTextBox);
frm.Controls.Add(submitButton);
frm.ShowDialog();
MessageBox.Show(Dts.Variables["tableName"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
void submitButton_Click(object sender, EventArgs e)
{
Dts.Variables["tableName"].Value = tableNameTextBox.Text;
frm.Close();
}
Ref: https://stackoverflow.com/a/4121557/325521

Manipulating a database in C++

I apologize if has been asked, and answered somewhere else, but I have been searching like crazy and can't find what I'm looking for.
OleDbConnection^ conn = gcnew OleDbConnection ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Milestone3testdatabase.accdb; Persist Security Info=True");
OleDbCommand^ com = gcnew OleDbCommand();
com->Connection = conn;
com->CommandText = "SELECT *FROM tblcity;";
System::Data::DataSet^ ds = gcnew System::Data::DataSet();
OleDbDataAdapter^ adapt = gcnew OleDbDataAdapter();
adapt->SelectCommand = com;
adapt->Fill(ds,"why");
dataGridView1->DataSource = ds->Tables["why"];
I am trying to figure out how to actually use the data I obtain from the database. I was shown how to put it into a gridview, BUT I don't want a gridview. I want be able to take 1 cell of the table and display it as text.
How do I convert the table into usable data for a C++ forms application?
Either modify your SELECT so that it returns only a single value by using SqlCommand.ExecuteScalar Method or extract the value from your table with the DataTable.Select Method and DataTable.Rows Property
myDataTable->Rows[rowNumber][columnNumber]

How to write condition on Filter String in code Reports Winforms devexpress?

I designed a report form and map fields with columns of tables from dataset. Now I need to set condition, so I used FilterString. Inside report form DetailReport, I wrote code like this:
DetailReport.FilterString = "[InvoiceNumber] = " + temp;
Now I need this same code (FilterString) for whole form that is top left of form Report Task some properties are available in that Data Source there we add dataset, Data Member, Data Adapter then FilterString is available.
Now I am able to add FilterString in Designer but I need to add FilterString in code ??
I Tried this one but not working
FilterString= "[InvoiceNumber] = " + temp"
I seggest you set the report FilterString property when you call for your XtraReport (for example : when you click on the print button of your form). Here is an code example :
private void simpleButton1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Some code like setting the report datasource
// Specify the report's filter string.
report.FilterString = "[InvoiceNumber] = myValue";
// Show the report's print preview.
pt.ShowPreviewDialog();
}
This code was taken from the DevExpress online documentation article : XtraReportBase.FilterString Property
Once you set the filter for the report, in the for you need to have it do:
public string p = "";
....
using (XtraReport_yourreport x = new XtraReport_yourreport ())
{
p = x.FilterString;
}

Gridview Columns to Excel

I'm using GridView to show data. And for exporting Gridview data into excel format,
I'm using a button - "Export to Excel". The downloading into Excel format or
Exporting into Excel is working perfectly. That GridView is showing total of 15 Columns.
But in the excel document its showing only 14 columns. What might be the problem?
Try this coding
In Button click
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Page.EnableViewState = false;
Response.AddHeader("Content-Disposition", "attachment;filename=report.xls");
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
and add the event
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
I hope the following link will help you
Export-GridView-to-Excel-without-losing-gridlines-in-Excel-file-in-ASPNet
Solution-ASPNet-GridView-Export-to-Excel-The-file-you-are-trying-to-open-is-in-a-different-format-than-specified-by-the-file-extension

ReportViewer databinding (WPF)

I have a rdlc file and I try to show it using report viewer control in WPF. My DataSource is called 'OfficeDataSet' and DataSet used in report is called 'Address'. I try to initialize report viewer (I put it in WindowsFormsHost) like this:
private void PrepareReport()
{
reportDataSource = new ReportDataSource();
officeDataSet = new OfficeDataSet();
adapter = new AddressTableAdapter();
adapter.Fill(officeDataSet.Address);
reportDataSource.Name = "OfficeDataSet_Address";
reportDataSource.Value = officeDataSet.Address;
viewerInstance.LocalReport.DataSources.Add(reportDataSource);
viewerInstance.LocalReport.ReportEmbeddedResource = "WpfApplication1.Reports.TestReport.rdlc";
viewerInstance.Location = new System.Drawing.Point(0, 0);
viewerInstance.RefreshReport();
}
but I got the message "A data source instance has not been supplied for the data source 'Address'".
Anybody know what can be wrong with this code? (I'm totally new in WPF and Reporting Services).
If i remember well, the datasource into the report file should have the same name (or maybe value) as the reportDataSource. So in your report file the datasource should be called "OfficeDataSet_Address".

Resources