I have writen code for to attach RDLC ReportViewer with a DataTable from a DataSet
But this error occurs: "A data source instance has not been supplied for the data source 'DataSet'."
aspx file code for Report Viewer
This is Report Viewer code
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<ServerReport ReportPath="Analysis.rdlc" />
<LocalReport ReportPath="Hospital\Analysis.rdlc">
</LocalReport>
</rsweb:ReportViewer>
C# File Code
This is code to fill Rows of DataTable in DataSet
ArrayList columns = new ArrayList();
columns.Add("Temp");
columns.Add("Humidity");
columns.Add("Rain");
columns.Add("Mosquitos");
columns.Add("FloodArea");
columns.Add("CloudyWeather");
columns.Add("FlowerVases");
columns.Add("IndequateSanitation");
ArrayList data = new ArrayList();
data.Add(Temp.SelectedItem.ToString());
data.Add(Humidity.SelectedItem.ToString());
data.Add(Rain.SelectedItem.ToString());
data.Add(Mosquitos.SelectedItem.ToString());
data.Add(FloodArea1.SelectedItem.ToString());
data.Add(CloudyWeather.SelectedItem.ToString());
data.Add(FlowerVases.SelectedItem.ToString());
data.Add(IndequateSanitation.SelectedItem.ToString());
BayesAnalysis bAnlysis = new BayesAnalysis();
ArrayList result = bAnlysis.classifyD(DiseaseList.SelectedItem.ToString(), columns, data);
List<double> pn = bAnlysis.PosNum();
NormalAnalysis nAnalysis = new NormalAnalysis();
AnalysisDataSet dss = new AnalysisDataSet();
for (int loop = 0; loop < pn.Count; loop++)
{
dss.ReportData.AddReportDataRow(loop, result[loop].ToString(), nAnalysis.NoPatient(nAnalysis.GetDiseaseID("Dengue"), nAnalysis.GetCityID(result[loop].ToString())), nAnalysis.TotalPatient(nAnalysis.GetDiseaseID("Dengue")), nAnalysis.diseasePercentageInCity(nAnalysis.GetDiseaseID("Dengue"), nAnalysis.GetCityID(result[loop].ToString())), pn[loop]);
}
This is code to Give Data Source to the Report Viewer
DataTable dtt = dss.ReportData;
ReportViewer1.Visible = true;
ReportDataSource datasource = new ReportDataSource("Analysis",dtt);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.Refresh();
Of the top of my head I think your line of code that says :
ReportDataSource datasource = new ReportDataSource("Analysis",dtt);
ReportDataSource datasource = new ReportDataSource("DataSet",dtt);
Basically it is to do with a name that you used in the RDLC file and when you supply the report dataset it must be named the sames.
Related
I'm trying to add a chart to a docx file using docx4j. I generated what i wanted in Word and with the help of the docx4j webapp i was able to get the corresponding java code. Unfortunately the generated docx file is said to be corrupted by Word. When trying to debug, I realised that if I commented out the line that added the drawing to the run, the file became readable. I can't figure out what's wrong. Below is my code and the link to what i tried to reproduce http://www.filedropper.com/graphique .
I'm using docx4j 8.2 and office 2016
Chart chartPart = new Chart();
Relationship chartRelationship = wordMLPackage.getMainDocumentPart().addTargetPart(chartPart);
chartPart.setJaxbElement(ChartSpace.createChartSpace());
DefaultXmlPart colorPart = new DefaultXmlPart(new PartName("/word/charts/colors1.xml"));
colorPart.setContentType(new ContentType("application/vnd.ms-office.chartcolorstyle+xml"));
colorPart.setRelationshipType("http://schemas.microsoft.com/office/2011/relationships/chartColorStyle");
chartPart.addTargetPart(colorPart);
colorPart.setDocument(new FileInputStream(new File("colors1.xml")));
DefaultXmlPart stylePart = new DefaultXmlPart(new PartName("/word/charts/style1.xml"));
stylePart.setContentType(new ContentType("application/vnd.ms-office.chartstyle+xml"));
stylePart.setRelationshipType("http://schemas.microsoft.com/office/2011/relationships/chartStyle");
chartPart.addTargetPart(stylePart);
stylePart.setDocument(new FileInputStream(new File("style1.xml")));
EmbeddedPackagePart embeddedPackagePart = new EmbeddedPackagePart(
new PartName("/word/embeddings/Microsoft_Excel_Worksheet.xlsx"));
embeddedPackagePart.setContentType(
new ContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
chartPart.addTargetPart(embeddedPackagePart);
embeddedPackagePart.setBinaryData(new java.io.FileInputStream(new File("data.xlsx")));
mainDocumentPart.getContent().add(addGraphic(factory, chartRelationship.getId()));
public static P addGraphic(ObjectFactory factory, String chartId) throws JAXBException {
P p = factory.createP();
// Create object for r
R r = factory.createR();
p.getContent().add(r);
// Create object for drawing (wrapped in JAXBElement)
Drawing drawing = factory.createDrawing();
JAXBElement<org.docx4j.wml.Drawing> drawingWrapped = factory.createRDrawing(drawing);
r.getContent().add(drawingWrapped);
org.docx4j.dml.wordprocessingDrawing.ObjectFactory dmlwordprocessingDrawingObjectFactory = new org.docx4j.dml.wordprocessingDrawing.ObjectFactory();
// Create object for inline
Inline inline = dmlwordprocessingDrawingObjectFactory.createInline();
drawing.getAnchorOrInline().add(inline);
org.docx4j.dml.ObjectFactory dmlObjectFactory = new org.docx4j.dml.ObjectFactory();
// Create object for graphic
Graphic graphic = dmlObjectFactory.createGraphic();
inline.setGraphic(graphic);
// Create object for graphicData
GraphicData graphicdata = dmlObjectFactory.createGraphicData();
graphic.setGraphicData(graphicdata);
graphicdata.setUri("http://schemas.openxmlformats.org/drawingml/2006/chart");
org.docx4j.dml.chart.ObjectFactory dmlchartObjectFactory = new org.docx4j.dml.chart.ObjectFactory();
// Create object for chart (wrapped in JAXBElement)
CTRelId relid = dmlchartObjectFactory.createCTRelId();
JAXBElement<org.docx4j.dml.chart.CTRelId> relidWrapped = dmlchartObjectFactory.createChart(relid);
graphicdata.getAny().add(relidWrapped);
relid.setId(chartId);
// Create object for cNvGraphicFramePr
CTNonVisualGraphicFrameProperties nonvisualgraphicframeproperties = dmlObjectFactory
.createCTNonVisualGraphicFrameProperties();
inline.setCNvGraphicFramePr(nonvisualgraphicframeproperties);
// Create object for extent
CTPositiveSize2D positivesize2d = dmlObjectFactory.createCTPositiveSize2D();
inline.setExtent(positivesize2d);
positivesize2d.setCx(5486400);
positivesize2d.setCy(3200400);
// Create object for effectExtent
CTEffectExtent effectextent = dmlwordprocessingDrawingObjectFactory.createCTEffectExtent();
inline.setEffectExtent(effectextent);
effectextent.setB(0);
effectextent.setL(0);
effectextent.setT(0);
effectextent.setR(0);
// Create object for docPr
CTNonVisualDrawingProps nonvisualdrawingprops = dmlObjectFactory.createCTNonVisualDrawingProps();
inline.setDocPr(nonvisualdrawingprops);
nonvisualdrawingprops.setDescr("");
nonvisualdrawingprops.setName("Graphique 1");
nonvisualdrawingprops.setId(1);
inline.setDistT(Long.valueOf(0));
inline.setDistB(Long.valueOf(0));
inline.setDistL(Long.valueOf(0));
inline.setDistR(Long.valueOf(0));
// Create object for rPr
RPr rpr = factory.createRPr();
r.setRPr(rpr);
// Create object for noProof
BooleanDefaultTrue booleandefaulttrue = factory.createBooleanDefaultTrue();
rpr.setNoProof(booleandefaulttrue);
return p;
}
I want to retrieve image from access database and want to show it on jlabel in netbeans. I've searched a lot on Google but I couldn't find the code fo retrieving image from MS Access. Can anyone help me in this matter please? I wrote the following code but it is not working. It's giving me the error
Record not found
DbConn obj = new DbConn();
String PatientID = getPid().getText();
String query = "Select [PatientEarImage] from PatientRecord where PatientID='"+PatientID+"'";
ResultSet rs= obj.Search(query);
try
{
while(rs.next())
{
byte[] img = rs.getBytes("PatientEarImage");
ImageIcon immgg;
immgg = new ImageIcon();
Image im = immgg.getImage();
Image myImg= im.getScaledInstance(getUpload().getWidth(), getUpload().getHeight(), Image.SCALE_SMOOTH);
ImageIcon newImage = new ImageIcon("PatientEarImage.jpg");
upload.setIcon(newImage);
}
}
catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "No Record Found");
}
Try this codes. I'm also used MS Access Database as a backend database
Blob filenameBlob = rs.getBlob("picture");
byte[] content = filenameBlob.getBytes(1L, (int) filenameBlob.length());
ImageIcon AA = new ImageIcon(content);
Image BB = AA.getImage();
Image CC = BB.getScaledInstance(FRAMEBOXPIC.getWidth(), FRAMEBOXPIC.getHeight(),
java.awt.Image.SCALE_SMOOTH);
AA = new ImageIcon(CC);
FRAMEBOXPIC.setIcon(AA);
I'm tring to fill a PDF file that has some different form fields, one of those field is a multi line field. I load the values from a txt file (I have to repeat this operation in batch so I've a single txt file for each pdf I've to fill)
My problem is with the \r\n present in the txt file... if I pass on each formfield it writes something as "My text\r\n on new line").
I've tried to use a stringbuilder and .AppendLine method and if I save it's content it correctly shows
My text
on new line
my input file is defined as
<map>
<campoModulo>lo_some_data</campoModulo>
<value>My text\r\non new line</value>
</map>
and here's the code I use to fill the pdf
internal void Process(string p)
{
string output = p.Replace(".pdf", "_new.pdf");
PdfReader reader = new PdfReader(p);
XmlDocument document = new XmlDocument();
document.Load("XML\\mapping.xml");
var items = document.SelectNodes("//map");
PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(
output, FileMode.Create));
var acro = pdfStamper.AcroFields;
if (items.Count > 0)
{
foreach (XmlNode item in items)
{
var campo = item.SelectSingleNode("campoModulo").InnerText;
var valore = item.SelectSingleNode("value").InnerText;
acro.SetField(campo, valore);
}
}
pdfStamper.FormFlattening = true;
pdfStamper.Close();
}
What am I doing wrong?
You have to replace the \r\n for the actual control codes. Try:
text = text.Replace(#"\r\n", "\r\n");
The following is my code and it is working with only one report.
rptbill = New CrystalReport1
rptexp = New ExpensesReport
rptmain = New MAINREPORT
rptbill.SetDataSource(dtincom)
rptexp.SetDataSource(dtexp)
frmCrystalReport.CrystalReportViewer1.ReportSource = rptmain
What I want is that my rptmain shows the field of my submenus rptbill and rptexp. I don't know how to get this to work.
Please help me with the below issue.
I have to read data from excel .
I have created JSPDynpage component and followd below link :
http://help.sap.com/saphelp_sm40/helpdata/en/63/9c0e41a346ef6fe10000000a1550b0/frameset.htm below is my code. I am trying to read excel file using apache poi 3.2 API
try
{
FileUpload fu = (FileUpload)
this.getComponentByName("myfileupload");
// this is the temporary file
if (fu != null) {
// Output to the console to see size and UI.
System.out.println(fu.getSize());
System.out.println(fu.getUI());
// Get file parameters and write it to the console
IFileParam fileParam = fu.getFile();
System.out.println(fileParam);
// Get the temporary file name
File f = fileParam.getFile();
String fileName = fileParam.getFileName();
// Get the selected file name and write ti to the console
ivSelectedFileName = fu.getFile().getSelectedFileName();
File fp = new File(ivSelectedFileName);
myLoc.errorT("#fp#"+fp);
try {
//
**FileInputStream file = new FileInputStream(fp);** --> error at this line
HSSFWorkbook workbook = new HSSFWorkbook(file);
myLoc.errorT("#workbook#"+workbook);
//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(0);
myLoc.errorT("#sheet#"+sheet);
//
} catch(Exception ioe) {
myLoc.errorT("#getLocalizedMessage# " + ioe.getLocalizedMessage());
}
Error :
#getLocalizedMessage# C:\Documents and Settings\10608871\Desktop\test.xls (The system cannot find the path specified)
at line FileInputStream file = new FileInputStream(fp);
I have created the PAR file and deploying it on server.
Thanks in Advance,
Aliya Khan.
i resolved the problem, i was passing the worng parameter instead of f
FileInputStream file = new FileInputStream(f);