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

New Post: Tables with Empty Cells

$
0
0
I'm creating a report where labels are on the top and left of a worksheet and data resides at the intersection of the labels. The following code is able to get me the appearance that I want. However, the document resulting from ClosedXML is 20MB in size. Most of the cells in the workbook are blank, and re-saving the document from Excel reduces the file size to 1MB.
public static void ToExcel (DataTable table, string fileName)
{
   var workbook = new XLWorkbook ();
   var worksheet = workbook.AddWorksheet (table.TableName);
   worksheet.Cell (1, 1).InsertTable (table);
   worksheet.SheetView.Freeze (1, 1);
   workbook.SaveAs (fileName);
}
I submitted this pull request with a fix for the issue. Is there anything I can do to facilitate it's adoption so that my team is not maintaining our own fork? Or, do you have another suggestion for how to work around this?
https://closedxml.codeplex.com/SourceControl/network/forks/ericlamb/closedxml/contribution/7561

New Comment on "Style Rows and Columns"

$
0
0
hi. Can i set the width and height of columns and rows with pixels? for example, ws.Row().Width = 20px;

Commented Unassigned: Locking cells doesn't work [9381]

$
0
0
Hello,

Looks like Worksheet.Cell(i,j).Style.Protection.Locked = true does not work like intended and the field is still editable. Is there something I am missing?

Thanks
Comments: Is there a way to unlock unused cells? The example above works but any unused cells are still set to locked and are thus uneditable unless you unprotect the sheet. I would like to be able to lock the header row but still allow the user to edit or copy and paste into empty rows. There is a setting to allow row inserts (which works) but not to allow the editing of any unused cells. Here is the code i used: ws.Style.Protection.SetLocked(false); ws.Row(1).Style.Protection.SetLocked(true); ws.Protect() .SetAutoFilter(true) .SetDeleteColumns(true) .SetDeleteRows(true) .SetFormatCells(false) .SetFormatColumns(false) .SetFormatRows(false) .SetInsertColumns(false) .SetInsertHyperlinks(true) .SetInsertRows(true) .SetObjects(true) .SetSelectLockedCells(true) .SetSelectUnlockedCells(true) .SetSort(true);

Commented Unassigned: Datetimes read as double [9091]

$
0
0
Hello friends,

I'm having a problem while reading an .xls using ClosedXML

I'm trying to copy a worksheet into an html table. However, when I get down to the cells that have dates on them (see sample.xls), this is what I get:

Cell.GetFormattedString() = $-4417089]d-mmm-yy
Cell.Value = + 41708.0 {Double}

So, the value is taken as a double instead of a Date, and I haven't found any way to correct this. Any clues?

My version of ClosedXML is 0.59.0.0. However, I've downloaded the latest one, and I get the same results.

Thank you!
Comments: The DateTime.FromOADate works even if the value wasn't originally a Date in Excel. I'm having the same issue where numbers and Dates with certain formats come through as Numbers. At that point, there is no way to tell if it was supposed to be a date or not. The cell Style.DateFormat is populated even when it's just a number (and not a date). Anyone know how to properly figure out which fields are actually dates and which ones aren't?

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: Solved the issue! See post above for details, but to simplify, this code didn't work when I tried to edit the file it created: ``` var wb = new XLWorkbook(); wb.Worksheets.Add(dataTable); wb.SaveAs(fileName); ``` Whereas, this code works great... if I create the file this way, I can edit it no problem: ``` var wb = new XLWorkbook(); wb.Worksheets.Add("Sheet1"); var ws = wb.Worksheet(1); ws.Cell("A1").Value = dataTable.AsEnumerable(); wb.SaveAs(fileName); ``` Hope this helps you! Thx. Great library!

New Post: how to add page break every 14 row

$
0
0
i got stuck on this solution and can't find any example
i use this but it break just first 14 row
ws.PageSetup.AddHorizontalPageBreak(14)

New Post: how to add page break every 14 row

New Post: how to add page break every 14 row

$
0
0
i do it on excel by macro
Sub InsertPageBreaks()
'Updateby20140618
Dim xLastrow As Long
Dim xWs As Worksheet
Set xWs = Application.ActiveSheet
xRow = Application.InputBox("Row", xTitleId, "", Type:=1)
xWs.ResetAllPageBreaks
xLastrow = xWs.Range("A1").SpecialCells(xlCellTypeLastCell).Row
For i = xRow + 1 To xLastrow Step xRow
xWs.HPageBreaks.Add Before:=xWs.Cells(i, 1)

Next
End Sub
so i need ClosedXML do it on generate

New Post: how to add page break every 14 row

$
0
0
Do a loop until the LastRowUsed incrementing by xRow instead of 1 and add the page breaks (just like you're doing in your macro).

New Post: how to add page break every 14 row

$
0
0
 Dim xrow As Integer = 0

                        Do Until xrow == ws.LastRowUsed()
                            ws.PageSetup.AddHorizontalPageBreak(xrow)
                            xrow += 13
                        Loop
i tried this but it doesn't work :'(

New Post: how to add page break every 14 row

$
0
0
Try until xrow >= last row used

If that doesn't work then be more specific on why/what doesn't work.

New Post: how to add page break every 14 row

$
0
0
i tried until xrow >= lastrowused() there is the same is
Operator '>=' is not defined for type 'Integer' and 'closedxml.excel.ixlrow

New Post: how to add page break every 14 row

New Post: how to add page break every 14 row

New Post: how to add page break every 14 row


New Post: how to add page break every 14 row

New Post: how to add page break every 14 row

$
0
0
You marked it as answered so I guess it's working now. Repro = reproduction = a way to reproduce the error (usually in the form a bare minimum project that can be run to show the error).

New Post: how to add page break every 14 row

$
0
0
the code is working but it's not working as i needed

New Post: how to add page break every 14 row

$
0
0
sorry @MDeleon it's my false code is work like a charm, i put a code on wrong button

New Post: getting Repaired Records: Worksheet properties from /xl/worksheets/sheet.xml part when export to excel

$
0
0
i getting this error
Repaired Records: Worksheet properties from /xl/worksheets/sheet.xml part
with my memory stream
      Response.Clear()
                        Response.Buffer = True
                        Response.Charset = ""
                        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                        Response.AddHeader("content-disposition", "attachment;filename=AllCaseExport " + ddlExportbTerm.SelectedValue + ".xlsx")

                        Using MyMemoryStream As New MemoryStream()
                            wb.SaveAs(MyMemoryStream)
                            MyMemoryStream.WriteTo(Response.OutputStream)
                            Response.Flush()
                            Response.End()

                        End Using
this error happen when export a long length file
Viewing all 1877 articles
Browse latest View live


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