I would like to dynamically add watermark to a report that is generated in Stimulsoft. The watermark can not be hard-coded and only appear if the report was generated in TEST environment.
I have a variable that checks if the report was created in test environment:
isTestEnv
Which means that if the watermark was added to the page the old fashioned way I would use:
if(isTestEnv == true) {
Page1.Watermark.Enabled = true;
} else {
Page1.Watermark.Enabled = false;
}
But this is not the case. I have to add the watermark when generating the report. Does anyone know how to?
The text is same on all pages it simply says "TEST". But how to push that into a report is the mystery.
you can use this code and set your water mark image in your report
Stimulsoft.Base.StiLicense.loadFromFile("../license.key");
var options = new Stimulsoft.Viewer.StiViewerOptions({showTooltips:false});
var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
var report = new Stimulsoft.Report.StiReport({isAsyncMode: true});
report.loadFile("Backgroundimg.mrt");
var page = report.pages.getByIndex(0);
page.watermark.image = Stimulsoft.System.Drawing.Image.fromFile('test.jpg');
page.watermark.aspectRatio = true;
page.watermark.imageStretch = true;
page.watermark.imageShowBehind= true;
report.renderAsync(function () {
viewer.report = report;
viewer.renderHtml("viewerContent");
});
You can set the report page watermark to some Report variable at design time and in your code set the value for the report variable.
Something like this:
StiReport report = new StiReport();
report.Load("REPORT_TEMPLATE_PATH");
//You can check if this variable exists or not using an if condition
report.Dictionary.Variables["WATERMARK_VARIABLE_NAME"] = "YOUR_TEXT";
report.Show();//or report.ShowWithWpf();
Related
I am trying to put data into cells using closedxml and according to their site we have to set parameters like this on the cells {{TestName}} but it won't work for me.
This is my code and I am not sure where I am going wrong.
const string outputFile = #"\\Reports\Output\Test.xlsx";
var template = new XLTemplate(#"\\Reports\Test.xlsx");
var test = new models.Test();
test.id = 1;
test.TestName = "ASDF";
test.TestScore = "303";
template.AddVariable(test) //also tried doing it like this.
template.AddVariable("TestScore", "232");
template.AddVariable("TestName", "TESTNAME");
template.SaveAs(outputFile);
Process.Start(new ProcessStartInfo(outputFile) { UseShellExecute = true });
And my excel template looks like this.
Solved it!
Just add template.Generate(); after adding the variables into the template.
Hi!!
i'm able to write charts to my XLSX file. But i'm stuck adding a simple title for every chart. No styles just simple plain text.
My code is like this:
String Dtitulo = "Hello chart";
DocumentFormat.OpenXml.Drawing.Charts.Title chartTitle = new DocumentFormat.OpenXml.Drawing.Charts.Title();
chartTitle.ChartText = new ChartText();
chartTitle.ChartText.RichText = new RichText();
DocumentFormat.OpenXml.Drawing.Paragraph parrafoTitulo = new DocumentFormat.OpenXml.Drawing.Paragraph();
DocumentFormat.OpenXml.Drawing.Run run = parrafoTitulo.AppendChild(new DocumentFormat.OpenXml.Drawing.Run());
run.AppendChild(new DocumentFormat.OpenXml.Drawing.Text(Dtitulo));
chartTitle.ChartText.RichText.AppendChild<DocumentFormat.OpenXml.Drawing.Paragraph>(parrafoTitulo);
chart.Title = chartTitle;
But when i open my file with excel says "file is corrupt" or something like that.
A bit late but I was faced with the same task, and I created an excel sheet and added manually a chart with a chart title, then opened the xml to understand what tags were needed. And after a while I got it working. moved everything in a small function as below:
So you can provide your chart object and the title you want to the below function and it will add the chart title.
Note:Im using Open XML SDK 2.0 for Microsoft Office
private void AddChartTitle(DocumentFormat.OpenXml.Drawing.Charts.Chart chart,string title)
{
var ctitle = chart.AppendChild(new Title());
var chartText = ctitle.AppendChild(new ChartText());
var richText = chartText.AppendChild(new RichText());
var bodyPr = richText.AppendChild(new BodyProperties());
var lstStyle = richText.AppendChild(new ListStyle());
var paragraph = richText.AppendChild(new Paragraph());
var apPr = paragraph.AppendChild(new ParagraphProperties());
apPr.AppendChild(new DefaultRunProperties());
var run = paragraph.AppendChild(new DocumentFormat.OpenXml.Drawing.Run());
run.AppendChild(new DocumentFormat.OpenXml.Drawing.RunProperties() { Language = "en-CA" });
run.AppendChild(new DocumentFormat.OpenXml.Drawing.Text() { Text = title });
}
And if you want a full example, you can review the official one here, and inject the above function in the right place (after the creation of the chart object) and it will add the chart title.
I'm using the ReportService2010 web service (e.g. http://[server]/ReportServer_WLTSQL05/ReportService2010.asmx?wsdl) to upload an SSRS report.
In the GUI front end I am able to go to the properties section of a report and select a check box to 'Hide in Tile View' and would like to perform the same action after uploading my report via the web service. How can I do that?
Currently my code looks like:
var reportProperty = new Property[0];
reportService.CreateCatalogItem(type, reportObjectName, folderPath, true, reportBytes, reportProperty, out warnings);
And I've tried adding different types to the Property array but not achieved success yet.
I've just managed to change this via:
var property = new Property { Name = "Hidden", Value = "true" };
var properties = new Property[1];
properties[0] = property;
reportService.SetProperties(reportObject.Path,properties);
So I went back to the original code and updated it to:
var reportProperty = new Property[1];
var hideProperty = new Property { Name = "Hidden", Value = hideFromTileView.ToString() };
reportProperty[0] = hideProperty;
reportService.CreateCatalogItem(type, reportObjectName, folderPath, true, reportBytes, reportProperty, out warnings);
And it all works now.
Using Visual Studio 2010 and Crystal Reports 13.0.
For the report, there is a prompt for the user to input a value. Then the report is generated with no problems.
If the user leaves the report.aspx page and comes back to run another report, the prompt does not show and the last report run is still there with the original value from the user.
Searching around for a solution, the only two found did not work:
//After the report loads
CrystalReportSource1.ReportDocument.ParameterFields.Clear();
Error:
You cannot add, remove or modify parameter fields using this method. Please modify the report directly.
Modify the report directly:
Right click the body of your Crystal Report
then goto:
Design -> Default Settings.. ->Reporting
Check the checkbox
Discard Saved Data When Loading Reports.
This did not work. The previous report still populates.
So, I now ask for a little insight on how to fix this problem.
As always, any suggestions are welcome.
Thanks
EDIT:
Here is the code behind for the report page. Many reports use this page....
CrystalReportSource1.Report.FileName = "reports\\" + fileName + ".rpt";
//CrystalReportSource1.Report.Parameters.Clear();
//CrystalReportSource1.Report = null;
//CrystalReportSource1.Report.Refresh();
if (!string.IsNullOrEmpty(Request.QueryString["item"]))
{
String Item = Request.QueryString["item"];
CrystalDecisions.Web.Parameter temp = new CrystalDecisions.Web.Parameter();
temp.Name = "Item";
temp.DefaultValue = Item;
CrystalReportSource1.Report.Parameters.Add(temp);
}
SqlConnectionStringBuilder settings = new SqlConnectionStringBuilder(MyConnectionString);
_crReportDocument = CrystalReportSource1.ReportDocument;
_crConnectionInfo.ServerName = settings.DataSource;
_crConnectionInfo.DatabaseName = settings.InitialCatalog;
_crConnectionInfo.UserID = settings.UserID;
_crConnectionInfo.Password = settings.Password;
//Get the table information from the report
_crDatabase = _crReportDocument.Database;
_crTables = _crDatabase.Tables;
//Loop through all tables in the report and apply the
//connection information for each table.
for (int i = 0; i < _crTables.Count; i++)
{
_crTable = _crTables[i];
_crTableLogOnInfo = _crTable.LogOnInfo;
_crTableLogOnInfo.ConnectionInfo = _crConnectionInfo;
_crTable.ApplyLogOnInfo(_crTableLogOnInfo);
}
You can try using this in your Page_Unload event.
Report.Close();
Report.Dispose();
That should get rid of the report when the page is unloaded and you will start fresh when the user comes back to the page.
There is a good example in this post here.
I found the solution!!!! -------- NOT
Add this line before all the code in my question above:
CrystalReportViewer1.ParameterFieldInfo.Clear();
Then load the file name and so forth.......
i have business object called "TeamMaster",
in which i define three properties,Id,Name & Flg.
in my .rdlc report i apply TeamMaster object as a data source,
now i write the following code in page load event of form in which i add report viewer control and i define my report as a local report.
using (RDLC_DEMO_DBEntities objdatabase = new RDLC_DEMO_DBEntities())
{
lstTeamMstr = objdatabase.TeamMasters.ToList();
}
this.TeamMasterBindingSource.DataSource = lstTeamMstr;
this.reportViewer1.RefreshReport();
when i check this code using debugging i get 6 records in TeamBindingSource,
but in windows report only displays six blank rows,
what is the problem?
Follow this code : >>
string path = HttpContext.Current.Server.MapPath(Your Report path);
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
// Add sub report even handler if you need
***ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportProcessingEventHandler);***
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue(Your object data-source);
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();
Here Subreport Even handler code
private void MySubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
{
//You can get parameter from main report
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you need like main report
//Now add sub report data source
e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}
If you need to create Drillthrough report than follow this link Click here for Drillthrough report