Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all 1877 articles
Browse latest View live

Commented Unassigned: DataRange.RowCount when no data in table [9408]

$
0
0
Hi,

I think there is a weird behavior in IXLDataTable.DataRange.RowCount().

My code:
var dataRange = worksheetMain.Range(cellTableStart, cellTableEnd);
var tableMData = dataRange.AsTable();

fileTotalRecords = tableMData.DataRange.RowCount();

If the original range contains:
1 header row
+2 data rows

The RowCount is 2.

If the range contains:
1 header row
+ No data

The RowCount is 1.

Looks like a bug?
Or is there an explanation?
Comments: It gives the wrong output so it's a bug.

Reviewed: ClosedXML 0.76.0 (ene 07, 2015)

$
0
0
Rated 2 Stars (out of 5) - very slow compared to other libraries as EPPlus :/

Created Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.

Created Unassigned: Reduce memory usage during SaveAs() [9410]

$
0
0
I'm trying to use ClosedXml to generate a large sheet (620K rows, 10 columns, CSV version approx 104 MB), loading the data and creating the sheets needs a lot of memory (approx 4 GB) but this is fine. But then when I try to SaveAs() I get an OutOfMemory exception when the process uses approx 9 GB of memory.

I believe the _problem_ is that the DOM approach is being used with the OpenXML SDK. Is there any chance this can be rewritten to use the streaming approach (i.e. using OpenXmlWriter)?

I don't have experience using the OpenXML SDK, but I would be willing to contribute if you can provide some pointers.

The simplest approach (least code impact which would seem to work in my particular situation) I considered was a two phase approach. First use the DOM approach to write an baseline file, then re-open the file using OpenXmlReader and write a replacement WorksheetPart using OpenXmlWriter basically copying what is there but creating a new SheetData in which the rows and their columns are streamed. But like I said I have no real experience is this area so this might be completely wrong.

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: Same problem. Same code - I get: Specified part does not exist in the package Please help... can't open a file.

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: More info... If I manually create a new Excel file, I can open it with the code above. However, if I use ClosedXML to create the file from scratch and save it... then I go back and try to open the file, I get the error message.

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: Please provide the code you are using to create the excel file. Which version of ClosedXML are you using.

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: Hi - thanks for the response! Code is: ``` // New file... var wb = new XLWorkbook(); wb.Worksheets.Add(dataSet.Tables[0]); wb.SaveAs(@"c:\\Users\\Dave\\Downloads\\output.xlsx"); ``` I loaded ClosedXML with nuget. Version is: ``` <package id="ClosedXML" version="0.76.0" targetFramework="net45" /> ``` Thanks for your help!

Reviewed: ClosedXML 0.76.0 (Jan 11, 2015)

$
0
0
Rated 5 Stars (out of 5) - This is a great tool to drastically reduce the amount of code it takes to create an OpenXML document. Great work on this library.

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: For me the issue was, file was in the format of "__Strict Open XML Spreadsheet__". Please let me know whether this format is supported by closed xml or not.

Created Unassigned: InsertData failes if at least one element is null [9411]

$
0
0
Hi,

```
<TestMethod()> Sub WriteNothing()

Dim workBook As New XLWorkbook(XLEventTracking.Disabled)
Dim workSheet As IXLWorksheet = workBook.Worksheets.Add("Sheet 1")

Dim array(3) As Object

array(0) = 1
array(1) = Nothing
array(2) = 2
array(3) = 3

workSheet.Range("A1").FirstCell.InsertData(array)

End Sub
```

workaround

```
public IXLRange InsertData(IEnumerable data) {
if (data != null && data.GetType() != typeof(String)) {
var ro = Address.RowNumber;
var maxCo = 0;
var isDataTable = false;
var isDataReader = false;
foreach (var m in data) {
var co = Address.ColumnNumber;

if (m == null) {
SetValue(m, ro, co);
co++;
}
else if (m.GetType().IsPrimitive || m is string || m is DateTime || m is Decimal) {
SetValue(m, ro, co);
co++;
}
else if (m.GetType().IsArray) { ....
```

regards,
Michael

Commented Unassigned: The specified package is invalid. The main part is missing. [9409]

$
0
0
I am using the closed XML for generating the excel template. After filling the data in the generated excel, I am trying to import the excel with data. It returns error "The specified package is invalid. The main part is missing." . I am using XLSX file.

```
try
{
var workbook = new XLWorkbook(FILE_PATH);
}
catch (Exception ex)
{
throw;
}
```

Please provide a solution.
Comments: So... updated code... slightly different issue. Use case #1: Use the code below to have the system create an Excel file, load it with data, and save the file... works. Use case #2: Manually create an Excel file (using Excel), save it, close it. Then use the code below to edit that file (i.e. update data)... works. Use case #3: Do use case #1 (i.e. create file using code). Then, use the code below to edit that file (i.e. update data)... FAILS. The error I get for that now is: "Range is invalid." Note about the code below: * The top part of the if statement creates a new file * The bottom part of the if statement edits an existing file * When creating new, it loads and formats the data nicely * Editing works, but the data is formatted poorly - that's why I'm trying to clean it up. It would be great if there were a way to simply load my DataTable into an existing worksheet to replace the data. * I don't want to delete the worksheet and re-add a new worksheet as we want the sheet to drive charts and reporting and deleting the sheet would break the links. I really want to just refresh the data. Code follows: ``` // Load data if (rdoNew.Checked) { // Create new file var wb = new XLWorkbook(); // Add worksheet - load datatable into sheet wb.Worksheets.Add(dataTable); // Save file string fileName = txtFilePath.Text + @"\" + cleanFileName(); // Putting in this var for ease of troubleshooting wb.SaveAs(fileName); } else { // Open existing file... var wb = new XLWorkbook(txtFilePath.Text); // Select first worksheet in workbook // TODO: Allow user to select worksheet var ws = wb.Worksheet(1); // Remove all data from worksheet ws.Columns("A:BB").Delete(); // TODO: Better way to do this? // Load column headers for (int i = 0; i < dataTable.Columns.Count; i++) { if (i > 25) { break; // TODO: Enhance/improve this so we can have column headers past column Z. This will likely be rare so leaving it for now. } ws.Cell(alphabet.Substring(i, 1) + "1").Value = dataTable.Columns[i].ColumnName; } // Load data var data = dataTable.AsEnumerable(); ws.Cell("A2").Value = data; // Format data ws.Columns().AdjustToContents(1,50); ws.Cell("A1").Select(); // Save file wb.Save(); } ``` The error happens on the last line of the edit: wb.Save(); If it helps, the stack trace is: ``` at ClosedXML.Excel.XLRangeAddress.get_FirstAddress() at ClosedXML.Excel.XLRangeAddress.Equals(Object obj) at ClosedXML.Excel.XLTable.get_FieldNames() at ClosedXML.Excel.XLWorkbook.<>c__DisplayClasse3.<GenerateSharedStringTablePartContent>b__dd(IXLTable t) at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action) at ClosedXML.Excel.XLWorkbook.<>c__DisplayClasse3.<GenerateSharedStringTablePartContent>b__dc(IXLWorksheet w) at ClosedXML.Excel.EnumerableExtensions.ForEach[T](IEnumerable`1 source, Action`1 action) at ClosedXML.Excel.XLWorkbook.GenerateSharedStringTablePartContent(SharedStringTablePart sharedStringTablePart, SaveContext context) at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath, SpreadsheetDocumentType spreadsheetDocumentType) at ClosedXML.Excel.XLWorkbook.Save() at Desktop_API.frmMain.btnGetData_Click(Object sender, EventArgs e) in c:\Users\...\frmMain.cs:line 91 ``` Thanks for any assistance!

Created Unassigned: Formula is broken when you copy [9412]

$
0
0
<Formula of the source cell>
=R[5]C-1

var wb = new XLWorkbook(@"C:\Sample.xlsx");
var wsSource = wb.Worksheet(1);
wsSource.CopyTo("Copy");
wb.SaveAs(@"C:\Sample.xlsx");

<Formula of the destination cell>
=R[5]C[-1]


Created Unassigned: Loading a new workbook fails under mono [9413]

$
0
0
I am unable to do one of the most basic things, open a new workbook under Ubuntu running monodevelop. The following code:
```
XLWorkbook wb = new XLWorkbook("input.xlsx");

```
throws an exception:

```
System.IO.IOException: Operation not valid when package is read-only
at System.IO.Packaging.Package.CheckIsReadOnly () [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id, Boolean loading) [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.LoadRelationships (System.Collections.Generic.Dictionary`2 relationships, System.IO.Stream stream) [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.get_Relationships () [0x00000] in <filename unknown>:0
at System.IO.Packaging.PackagePart.GetRelationships () [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.PackagePartRelationshipPropertyCollection..ctor (System.IO.Packaging.PackagePart packagePart) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart parent, System.Uri uriTarget, System.String id, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships (DocumentFormat.OpenXml.Packaging.OpenXmlPackage openXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart sourcePart, DocumentFormat.OpenXml.Packaging.RelationshipCollection relationshipCollection, System.Collections.Generic.Dictionary`2 loadedParts) [0x00000] in <filename unknown>:0
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load () [0x00000] in <filename unknown>:0
```

The file has all rwx permissions. Is Linux not supported somehow? Am I making some n00b mistake?

Created Unassigned: Page break crashes workbook in saving. [9414]

$
0
0
Hi! Thank you for good library.

I'm troubled by a simple problem.
Sometimes, workbook is crashed in saving.
In order to ascertain reproducibility conditions, I prepared simple program.
it only repeat 'open' and 'save' to same file.

```
class Program
{
static void Main(string[] args)
{
var book = new XLWorkbook(@"..\..\data\original.xlsx");
book.SaveAs(fileName(0));

for (int i = 0; i < 100; i++)
{
book = new XLWorkbook(fileName(i));
book.SaveAs(fileName(i + 1));
}
}

private static string fileName(int i)
{
return string.Format(@"..\..\data\{0}.xlsx", i);
}
}
```

When not include page break, it's no problem.
When include page break, however, workbook is crashed at about 10th roop.
Finally, memory overflow occurs.

Avoiding this problem, I add some cords deleting all of page break.
Do you have any other good ideas?

New Post: Loading SSRS Excel spreadsheet throws Object reference not set error

$
0
0
I have the same problem .
"Object reference not set to an instance of an object."
I didn't have this problem when we called XLWorkbook on a SSRS 2008 Excel file but now i got the problem when we upgraded SQL 2014.

Created Unassigned: Comment.Delete() crashes workbook [9415]

$
0
0
Hi!

I'm troubled by a simple problem.
Sometimes, workbook including comments is crashed by deleting comment.
In order to ascertain reproducibility conditions, I prepared simple program.

```
class Program
{
static void Main(string[] args)
{
var book = new XLWorkbook();
book.AddWorksheet("comment");
book.Worksheet("comment").Cell(1, 1).Comment.AddText("test");
book.SaveAs("test.xlsx");

book = new XLWorkbook("test.xlsx");
book.Worksheet("comment").Cell(1, 1).Comment.Delete();
book.Save();
}
}
```

When I open this workbook in MS EXCEL, dialog appears for repairs workbook.
Does delete comments not available?

Created Unassigned: WorkBook opening exception with message "Identifier expected" [9416]

$
0
0
When I trying to open workbook I catch exception.
Code:
```
var doc = new XLWorkbook(workBookFileName);
```

StackTrace:
```
в ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg)
в ClosedXML.Excel.CalcEngine.CalcEngine.GetToken()
в ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare()
в ClosedXML.Excel.CalcEngine.CalcEngine.ParseExpression()
в ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
в ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
в ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
в ClosedXML.Excel.XLWorksheet.Evaluate(String expression)
в ClosedXML.Excel.XLCell.get_Value()
в ClosedXML.Excel.XLCell.TryGetValue[T](T& value)
в ClosedXML.Excel.XLCell.GetValue[T]()
в ClosedXML.Excel.XLCell.GetString()
в ClosedXML.Excel.XLTable.get_FieldNames()
в ClosedXML.Excel.XLTable.HeadersRow()
в ClosedXML.Excel.XLTable.InitializeValues(Boolean setAutofilter)
в ClosedXML.Excel.XLTable..ctor(XLRange range, String name, Boolean addToTables, Boolean setAutofilter)
в ClosedXML.Excel.XLRange.CreateTable(String name, Boolean setAutofilter)
в ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
в ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName)
в ClosedXML.Excel.XLWorkbook.Load(String file)
в ClosedXML.Excel.XLWorkbook..ctor(String file, XLEventTracking eventTracking)
в ClosedXML.Excel.XLWorkbook..ctor(String file)
в RoadDB.UI.Forms.OpenXmlExcelHelper.ExcelToDataTable(String workBookFileName, String workSheetName, String tableName, Boolean skipHeader, Boolean skipHiddenRow) в c:\Users\Kutuzov\Documents\Visual Studio 2012\Projects\RoadDb2013\RoadDB\Helpers\OpenXmlExcelHelper.cs:строка 157
```
Inner Exception: null


Created Unassigned: Problem opening created spreadsheet in open office [9417]

$
0
0
I haved used this example to create a spreadsheet. The resulting spreadsheet will open fine in the Microsoft Execel Previewer but gets a general i/o error when I try to open it in OpenOffice Calc.

var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
workbook.SaveAs("HelloWorld.xlsx");

Any ideas as to what I am doing wrong.

New Post: proctect/lock specific cells

$
0
0
dice12345 wrote:
Hi,

I cannot seem to be able to figure out how to lock specific cells from any type of editing and ranges of cells.

If someone can give me a small example it would be very appreciated.

Thanks,
Is this possible using ClosedXml? The example given does not accomplish this. How does one lock specific cells without locking the entire sheet?
Viewing all 1877 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>