how to update excelsheet using java jxl - jxl

I want to update my existing excelsheet using java jxl.I gone through many links but not found the solution please refer
Before update excelsheet screenshoot
after update excelsheet screenshoot
public void writeExcel() {
String xlFilePath="test\\Resources\\Data\\dataExcel.xls";
String sheetName="loginSheet";
Workbook existingWorkbook = Workbook.getWorkbook(new File(xlFilePath));
WritableWorkbook workbookCopy = Workbook.createWorkbook(new File("output.xls"), existingWorkbook);
WritableSheet sheetToEdit = workbookCopy.getSheet(sheetName);
WritableCell cell;
Label label = new Label(2, 4, "value");
cell = (WritableCell) label;
sheetToEdit.addCell(label);
workbookCopy.write();
workbookCopy.close();
}

Related

How to enable external images at rdlc dotnet core

I want to pass an image as parameter to my RDLC in dotnet core using enableexternalimage properity.
I found the answer and these the steps
//define the paramters Dictionary
Dictionary<string, string> Param = new Dictionary<string, string>();
//get the image
string ImagePath = $"{ this._environment.WebRootPath }\\car.png";
Bitmap bitMapIm = new System.Drawing.Bitmap(ImagePath);
Graphics graphicIm = Graphics.FromImage(bitMapIm);
//the value that will be sended to the rdlc
string ImageAsParamter = "";
//transform the image ToBase64String
using (var image = new Bitmap(ImagePath))
{
using (var ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Png);
ImageAsParamter = Convert.ToBase64String(ms.ToArray());
}
}
//assign the parameter value
Param.Add("ImageDamages", ImageAsParamter);
//and finally add image to your rdlc with the following properties.
Image Parameter Properties

Unity, loading image from Sqlite

hi guys this is my first time using Sqlite, i managed to retrieve the text and display it, however the image shows a red question mark even tho i followed this : unity sqlite tutorial
here is my code :
private void readQuestionsFromDB(){
string conn = "URI=file:" + Application.dataPath + "/quizdb.s3db"; //Path to database.
IDbConnection dbconn;
dbconn = (IDbConnection) new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT id, statement, answer, image " + "FROM questions";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
string statement = reader.GetString(1);
answerint = reader.GetInt32(2);
byte[] img = (byte[])reader["image"];
Question q = new Question(statement, answer, img);
questions.Add(q);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
Then i try to display the image from the start method :
readQuestionsFromDB();
statement.text = questions[0].statement;
Texture2D tex = new Texture2D(800,400); //image is 800/400
tex.LoadImage(questions[0].image);
image.GetComponent<Image>().sprite = Sprite.Create(tex, new Rect(0,0,tex.width,tex.height),new Vector2(0.5f, 0.5f));
Here is the outcome :
image
Thank you in advance for your help!

convert system.data.linq.binary to byte[]

I am storing bytes in a database table. When I retrieve it with Linq 2 sql I get the return type in system.data.linq.Binary.
I am not able to convert the system.data.linq.binary to byte array(byte[]).
How do I convert it?
///my datacontext
var db = new db();
//key is an value from user
var img = from i in db.images
where i.id == key
select i.data;
the i.data is in linq.binary I want it to be in byte[].
I tried with (byte[])img but it did not work.
Have you tried calling ToArray() on i.data?
var img = from i in db.images
where i.id == key
select i.data.ToArray();
System.Data.Linq.Binary has a ToArray method just for that purpose.
Probably its too late by now but may help others :)
//testTable PK:ID, binaryData :binary(32)
public void insertDummyData()
{
DBML.testTable v = new DBML.testTable ();
v.ID = 1;
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
v.binaryData = new System.Data.Linq.Binary(encoding.GetBytes("11111111000000001111111100000000"));
db.testTable.InsertOnSubmit(v);
db.SubmitChanges();
}
Or else, Click on the Binary field from .dbml file, open properties and then change the field type from Binary to byte[] as found here
(byte[])linqBinaryField.ToArray()
You can try MemoryStream. I wrote a function in my project to convert an image to byte array like the following:
public static byte[] Image2ByteArr(string filename)
{
Bitmap bm = new Bitmap(getPath(filename));
MemoryStream ms = new MemoryStream();
bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
Hope that helpful for you!

How to add image dynamically in the jasper reports in java

Hii Guys !!!
I designed a jasper report to export into pdf which contains image that is stored in my local machine.Now As per my need i need to add the image dynamically from the projects classpath .Below I am posting my code.plz guys help me how to add image dynamically ...
File tempFile = File.createTempFile(getClass().getName(), ".pdf");
try {
FileOutputStream fos = new FileOutputStream(tempFile);
try {
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("jasperpdf.jasper");
try {
String datum1 = request.getParameter("fromdate");
String datum2 = request.getParameter("todate");
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MM-yyyy");
Date date = sdfSource.parse(datum1);
Date date2 = sdfSource.parse(datum2);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
datum1 = sdfDestination.format(date);
System.out.println(datum1);
datum2 = sdfDestination.format(date2);
System.out.println(datum2);
String strQuery = "";
ResultSet rs = null;
conexion conexiondb = new conexion();
conexiondb.Conectar();
strQuery = "Select calldate,src,dst,duration,disposition,cdrcost from cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'";
rs = conexiondb.Consulta(strQuery);
JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(rs);
JasperRunManager.runReportToPdfStream(reportStream, fos, new HashMap(), resultSetDataSource);
rs.close();
Is it working when you have provided the relative path of the image? i.e. images/image.jpg You should have a folder named images in your project and inside that there should be the file image.jpg ..
i'm newbie for jasper report, may be this code useful for you
private static JRDesignImage getImage(int x_postion, int y_position, int width, int height,ScaleImageEnum scale_type, HorizontalAlignEnum align_type,
JRDesignExpression expression) {
JRDesignImage image = new JRDesignImage(null);
image.setX(0);
image.setY(8);
image.setWidth(97);
image.setHeight(50);
image.setScaleImage(ScaleImageEnum.RETAIN_SHAPE);
image.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
image.setExpression(expression);
// TODO Auto-generated method stub
return image;
}
then add
band = new JRDesignBand();
band.setHeight(73);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$P{imagePath}");
// jasperDesign.addField();
band.addElement(getImage(0,8,97,50,ScaleImageEnum.RETAIN_SHAPE,HorizontalAlignEnum.LEFT,expression));

getting error while Inserting data while using RadControls

Error:
Unable to update the EntitySet 'ClientFeedBack' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
Code:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
ProTrakEntities1 objEntity = new ProTrakEntities1();
TextBox txtTitle = DetailsView1.FindControl("txtTask") as TextBox;
RadComboBox cmbStatus = DetailsView1.FindControl("cmbStatus") as RadComboBox;
RadComboBox cmbTaskType = DetailsView1.FindControl("cmbTasktype") as RadComboBox;
RadComboBox cmbTaskPriorty = DetailsView1.FindControl("cmbPriority") as RadComboBox;
string Description = (DetailsView1.FindControl("RadEditor1") as RadEditor).Content;
ClientFeedBack objResource = new ClientFeedBack();
objResource.Title = txtTitle.Text;
objResource.Description = Description;
objResource.TaskPriorityID = Convert.ToInt32(cmbTaskPriorty.SelectedValue);
objResource.TaskTypeID = Convert.ToInt32(cmbTaskType.SelectedValue);
objEntity.AddToClientFeedBacks(objResource);
objEntity.SaveChanges();
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);
}
My table name is ClientFeedBack.
Check for the primary key, check if you table ClientFeedBack has primary key defined or not.

Resources