"Repaired Records: String properties from /xl/sharedStrings.xml part (Strings)" error while opening SSRS exported excels merged using EPPlus package - epplus

I am exporting SSRS reports into to individual excel files and I am merging them into one file using EPPlus. Merge happens successfully but I get following error when I try to open the file in Excel.
I dropped report data to produce empty report but it still gives me this error. I could merge some other SSRS report files without any issue though. I wonder if there is any option or setting in EPPlus I should turn on/off.
Repaired Records: String properties from /xl/sharedStrings.xml part (Strings)
I am providing both XML files (from /xl/sharedStrings.xml after unzipping xlsx) here with before and after Excel fixed the worksheet. My apology but I am not formatting XML on purpose to retain all tags in original form.
Before Excel Repair (As is from EPPlus merged file):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="6"><si><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Tahoma"></rFont></rPr><t xml:space="preserve">Data Exceptions - Warnings</t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b val="0"></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Verdana"></rFont></rPr><t xml:space="preserve"></t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="18"></sz><color rgb="FF000000"></color><rFont val="Tahoma"></rFont></rPr><t xml:space="preserve">Summary</t></r></si><si><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b val="0"></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="10"></sz><color rgb="FF000000"></color><rFont val="Calibri"></rFont></rPr><t xml:space="preserve"> Execution Time: </t></r><r xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><rPr><b></b><i val="0"></i><strike val="0"></strike><u val="none"></u><sz val="10"></sz><color rgb="FF000000"></color><rFont val="Calibri"></rFont></rPr><t xml:space="preserve">11/14/2019 12:03:07 PM</t></r></si><si><t>Loan Number</t></si><si><t>Asset Type</t></si><si><t>Data Exception Name</t></si><si><t># Of Loans</t></si></sst>
After Excel Repair (After excel repaired the original file and saved it in Excel):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="6"><si><t>Data Exceptions - WarningsSummary</t></si><si><r><rPr><sz val="10"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t xml:space="preserve"> Execution Time: </t></r><r><rPr><b/><sz val="10"/><color rgb="FF000000"/><rFont val="Calibri"/></rPr><t>11/14/2019 12:03:07 PM</t></r></si><si><t>Loan Number</t></si><si><t>Asset Type</t></si><si><t>Data Exception Name</t></si><si><t># Of Loans</t></si></sst>
Here is the code for merging Excel files in case I am missing anything here. By the way, I don't have this issue with same files merged using Office InterOp. But, I wanted to avoid using InterOp which has issues of its own. Any help/tips would be great. Thanks
private string MergeUsingEPPlus(List<String> ExcelFiles, string resultFile)
{
using (ExcelPackage masterPackage = new ExcelPackage(new FileInfo(resultFile)))
{
foreach (var file in ExcelFiles)
{
using (ExcelPackage pckg = new ExcelPackage(new FileInfo(file)))
{
foreach (var sheet in pckg.Workbook.Worksheets)
{
//check name of worksheet, in case that worksheet with same name already exist exception will be thrown by EPPlus
string workSheetName = sheet.Name;
foreach (var masterSheet in masterPackage.Workbook.Worksheets)
{
if (sheet.Name == masterSheet.Name)
{
workSheetName = string.Format("{0}_{1}", workSheetName, DateTime.Now.ToString("yyyyMMddhhssmmm"));
}
}
//add new sheet
masterPackage.Workbook.Worksheets.Add(workSheetName, sheet);
}
}
}
//masterPackage.Save();
masterPackage.SaveAs(new FileInfo(resultFile));
}
}

I've had the same issue. The root cause was that Microsoft Excel has a character limit of 32,767 characters in each cell and some of my values were longer.
Anyway, the reason may vary from case to case, so I'll try to describe the universal way of identifying the issue.
Open the file with Excel and let him to restore the document.
Save a restored copy.
Now we have two documents, one is original and one is restored by Excel. Lets use the fact that xlsx format is actually an archive.
Rename original and restored files. Change extension to zip.
Extract both files.
Open both folders and go to file from Excel error message (xl/sharedStrings.xml)
Open both files and compare them.
I use Notepad++ with Compare plugin. By the way, first comparison may show a lot of insignificant differences. You can use "replace all" feature to make them the same in both files.
The difference you got after all manipulations most probably is the reason of Excel error.

Related

How to insert data into ms access db using text boxes? [duplicate]

I have following C# code in a console application.
Whenever I debug the application and run the query1 (which inserts a new value into the database) and then run query2 (which displays all the entries in the database), I can see the new entry I inserted clearly. However, when I close the application and check the table in the database (in Visual Studio), it is gone. I have no idea why it is not saving.
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlServerCe;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
string fileName = "FlowerShop.sdf";
string fileLocation = "|DataDirectory|\\";
DatabaseAccess dbAccess = new DatabaseAccess();
dbAccess.Connect(fileName, fileLocation);
Console.WriteLine("Connected to the following database:\n"+fileLocation + fileName+"\n");
string query = "Insert into Products(Name, UnitPrice, UnitsInStock) values('NewItem', 500, 90)";
string res = dbAccess.ExecuteQuery(query);
Console.WriteLine(res);
string query2 = "Select * from Products";
string res2 = dbAccess.QueryData(query2);
Console.WriteLine(res2);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e);
Console.ReadLine();
}
}
}
class DatabaseAccess
{
private SqlCeConnection _connection;
public void Connect(string fileName, string fileLocation)
{
Connect(#"Data Source=" + fileLocation + fileName);
}
public void Connect(string connectionString)
{
_connection = new SqlCeConnection(connectionString);
}
public string QueryData(string query)
{
_connection.Open();
using (SqlCeDataAdapter da = new SqlCeDataAdapter(query, _connection))
using (DataSet ds = new DataSet("Data Set"))
{
da.Fill(ds);
_connection.Close();
return ds.Tables[0].ToReadableString(); // a extension method I created
}
}
public string ExecuteQuery(string query)
{
_connection.Open();
using (SqlCeCommand c = new SqlCeCommand(query, _connection))
{
int r = c.ExecuteNonQuery();
_connection.Close();
return r.ToString();
}
}
}
EDIT: Forgot to mention that I am using SQL Server Compact Edition 4 and VS2012 Express.
It is a quite common problem. You use the |DataDirectory| substitution string. This means that, while debugging your app in the Visual Studio environment, the database used by your application is located in the subfolder BIN\DEBUG folder (or x86 variant) of your project. And this works well as you don't have any kind of error connecting to the database and making update operations.
But then, you exit the debug session and you look at your database through the Visual Studio Server Explorer (or any other suitable tool). This window has a different connection string (probably pointing to the copy of your database in the project folder). You search your tables and you don't see the changes.
Then the problem get worse. You restart VS to go hunting for the bug in your app, but you have your database file listed between your project files and the property Copy to Output directory is set to Copy Always. At this point Visual Studio obliges and copies the original database file from the project folder to the output folder (BIN\DEBUG) and thus your previous changes are lost.
Now, your application inserts/updates again the target table, you again can't find any error in your code and restart the loop again until you decide to post or search on StackOverflow.
You could stop this problem by clicking on the database file listed in your Solution Explorer and changing the property Copy To Output Directory to Copy If Newer or Never Copy. Also you could update your connectionstring in the Server Explorer to look at the working copy of your database or create a second connection. The first one still points to the database in the project folder while the second one points to the database in the BIN\DEBUG folder. In this way you could keep the original database ready for deployment purposes and schema changes, while, with the second connection you could look at the effective results of your coding efforts.
EDIT Special warning for MS-Access database users. The simple act of looking at your table changes the modified date of your database ALSO if you don't write or change anything. So the flag Copy if Newer kicks in and the database file is copied to the output directory. With Access better use Copy Never.
Committing changes / saving changes across debug sessions is a familiar topic in SQL CE forums. It is something that trips up quite a few people. I'll post links to source articles below, but I wanted to paste the answer that seems to get the best results to the most people:
You have several options to change this behavior. If your sdf file is part of the content of your project, this will affect how data is persisted. Remember that when you debug, all output of your project (including the sdf) if in the bin/debug folder.
You can decide not to include the sdf file as part of your project and manage the file location runtime.
If you are using "copy if newer", and project changes you make to the database will overwrite any runtime/debug changes.
If you are using "Do not copy", you will have to specify the location in code (as two levels above where your program is running).
If you have "Copy always", any changes made during runtime will always be overwritten
Answer Source
Here is a link to some further discussion and how to documentation.

Unpack a rar file

Okay, so I have searched for dll files that will allow me to unrar files and I was able to find quite a few such as unrar.dll, chilkat, sharpcompress and some more but I wanted to use the one provided by Rar themselves.
So I referenced the DLL file in my project and imported it. I was using unrar.dll.
But I wasn't able to find any up to date code to allow me to test and try things out. All the examples I found were either not up to date or not for Vb.net.
I also tried the official example, which came in the installation but that didn't work even after I fixed it and when I tried to use the code I always got an error for
object reference not set to an instance of an object
I just want to unrar a rar file from a specific location to the root directory of my program so if my program was on the desktop I want it to unrar a file in My documents and extract the files to my desktop.
If you just want to unrar files, I Was able to do that with SharpCompress
First I created a new VB.Net App and added a reference to SharpCompress.dll before using this code to extract all the files from a Rar file.
'Imports
Imports SharpCompress.Archives
Imports SharpCompress.Common
'Unrar code
Dim archive As IArchive = ArchiveFactory.Open("C:\file.rar")
For Each entry In archive.Entries
If Not entry.IsDirectory Then
Console.WriteLine(entry.Key)
entry.WriteToDirectory("C:\unrar", New ExtractionOptions With
{.ExtractFullPath = True, .Overwrite = True})
End If
Next
More code samples
for those who will try in vb.net the extract options are renamed and used as
Dim options As New ExtractionOptions With {
.ExtractFullPath = True,
.Overwrite = True
}
entry.WriteToDirectory(Application.StartupPath, options)

Opening an excel file in vb.net

Is there a way to just call Open() function with the file name and extension (xlApp.Workbooks.Open(“Test.xlsx”)) and have it search your whole computer for the file? I know you can open the file if it has a specified path like "c:\docume~1(username)\desktop\Test.xlsx" but I was wondering if there's a way to search your whole computer for the file without specifying the whole path.
You could use:
string[] fileNames = Directory.GetFiles("C:\\", "yourFile.xls",
SearchOption.AllDirectories);
or
var txtFiles = Directory.EnumerateFiles("C:\\", "yourFiles.xls",
SearchOption.AllDirectories);
but you should read carefully the documentation (GetFiles) (EnumerateFiles) on MSDN because there are numerous facts to be prepared of. (Unauthorized Access Exceptions, Search times)

Is it possible run selenium test with input data in excel?

I use Selenium Web Driver in Eclipse with JUnit. I compose my main test - common for all other, on the begining I set my input data (which is different for each test):
String update_f="//*[#id='columnTitle2']/input";
String update_u="dscr";
String name_p="Test";
String[] link=new String [] {"001","01"};
String[] lov_name= new String [] {"Work","Machine"};
Is it possible to set this data in excel file and than just change this file if I want execute specific test (actually set specific data)?
It is possible my friend,with the help some external jars to handle Excel spread sheets.
U can choose
a. JXL Jar ( which is easy to use and is sufficient for normal functionalities like read and write) - http://www.andykhan.com/jexcelapi/tutorial.html
b. Apache poi jar - http://onjava.com/pub/a/onjava/2003/04/16/poi_excel.html
Add these external jars into eclipse.
create an excel file with different input values.
Read and pass these values from excel through the jars.
currently im working with JXL it is good.

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)