Reading xlsx file using SmartXLS - xlsx

Can anybody please tell me how to use SmartXLS to read xlsx file by giving an example?

WorkBook workBook = new WorkBook();
workBook.readXLSX("test.xlsx");

Related

How to access shapefiles in OpenShift

I have shapefiles in my jar which is deployed in OpenShift. I'm able to access these files from my local environment by using "File sourceFile = new ClassPathResource("src/main/resources/CountryBoundaries.shp).getFile();". However, in OpenShift, my service complains that it couldn't find it. I have tried InputStream but I get an error in my IDE because the file is not a text file. Below is my code:
File sourceFile = new ClassPathResource("src/main/resources/CountryBoundaries.shp").getFile();
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);
featureSource = store.getFeatureSource();
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName();
What am I missing? I'll appreciate any help as I've been struggling with this for quite a while now. Thanks.
I found a solution by changing URL to URI and then doing a toURL(). See below:
URI sourceFile = new ClassPathResource("PoliticalSubdivisionBoundaries.shp").getURI();
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile.toURL());
featureSource = store.getFeatureSource();
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName();
Hope this helps someone in the future. Shapefiles are complex and cannot be accessed the usual way like using inputStream and such. Cheers!

SSIS Macro not able to open Excel

I have following code to open the excel file.
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Open("c:\\Temp\\MyExcel.xls"); // absolute path needed
Thread.Sleep(30000);
xlApp.Quit();
If I place this code in any code file using website or window application it runs fine, it also opens my excel file which automatically runs macros and complete the logic in it.
But when I put the same code in SSIS and try to run the code, it doesn't work.
Can anyone please guide me further in this? It is getting critical.
Thanks in advance.

Visual basic closing a file

I'm using Visual basic 2012, and I'm experimenting with manipulating .txt files. I've managed to make a button to create them, but the button I made to delete them always runs into and error, claiming the file is still in use. I've tried to write code to close the file, but no success. The closest I've gotten was when I tried
FileStream.Close("C:\Testfile")
But I get an error saying that It needs to be linked to an object. I don't have the faintest idea what it mean by object, and I don't have any other ideas
Can someone tell me what I need to do to fix this, or alternatively, another solution
You must make sure that the code you have for creating the file, closes that file as well after the job is done:
Dim sw As StreamWriter = New StreamWriter("C:\Testfile")
' write to the file here, like:
sw.Write("...")
' ...etc, and at the end of the job, close the file:
sw.Close()
To actually delete a file from the file system, use:
File.Delete("C:\Testfile")
I suspect the problem that you are having could be because the file is still open when you are trying to delete it.
Add your file manipulation code inside a Using block as explained in this MSDN article. By using this technique you will not have to remember to close files yourself as it will happen automatically once you have left the Using block.
Dim filePath As String = "hello.txt"
Using openedFile As FileStream = File.Open(filePath, FileMode.OpenOrCreate)
'File is OPEN
Dim bytes() As Byte = Encoding.ASCII.GetBytes("Hello World")
openedFile.Write(bytes, 0, bytes.Length)
End Using
'File is CLOSED and can be deleted
File.Delete(filePath)
You can also use this technique for any other objects that implement IDisposable such as StreamReader and StreamWriter.

Windows Form Application - Save file from Web URL into Database

I am currently trying to read a file from the Web and save this into my SQL Database but am experiencing difficulty in saving the file. What is getting inserted into the database as the file data seems to be wrong so gives an error on trying to read it back from the database. The following is the code I am using:
Dim objWReq As WebRequest
Dim objWResp As WebResponse
objWReq = HttpWebRequest.Create(CVDocumentURL)
objWResp = objWReq.GetResponse()
Dim objStream As System.IO.Stream
objStream = objWResp.GetResponseStream
Dim objData As Byte() = ReadFully(objStream)
objWResp.Close()
Dim ObjAdapter As New TableAdapters.Method
ObjAdapter.InsertFile(ApplicationId, UserId, VacancyId, DateCreated, CoveringLetter, CVDocumentURL, Nothing, objWResp.ContentType, FileName, objWResp.ContentLength, objData)
On checking the properties of objData they all seem to be fine before doing the insert. Does anyone know what is going wrong here?
Thanks

How to modify an XML file present in a folder in the Silverlight project?

I'm trying to read & modify an XML file present in the Silverlight project from a view's code behind.
This is how I've read & modified the XML file:
StreamResourceInfo s = Application.GetResourceStream(new Uri("XML/Settings.xml", UriKind.Relative));
XElement doc = XElement.Load(s.Stream, LoadOptions.None);
IEnumerable<XElement> settingElement = (from b in doc.Descendants(
"setting")
select b).Take(1);
if (settingElement.Count<XElement>() > 0)
{
foreach (var node in newsIdNode)
{
node.Remove();
}
}
What I want to do now, is to save the XML file. I tried the following:
doc.Save(s.Stream, SaveOptions.None);
But got a runtime error that the stream is not writable.
How can I save changes to this XML file?
You can't- the stream is only for reading. If you want to save something consider isolated storage, saving to a file or persisting state via Web services.

Resources