OpenXML Excel file corruption, DataValidations - excel

I am creating an excel file using OpenXML SDK 2.0 from a WPF application. The excel file has multiple sheets, data validations for dropdown cells, Formulas, and StyleSheets applied. It works fine creating excel rows of around 17,500 in Sheet1 and 17,500 in Sheet2 as well. However, when the number of rows reaches 25,000 for both Sheet1 and Sheet2 the file gets corrupted i.e. while opening the file it gives an error "We found a problem with the content in file.xlsx. Do you want to recover as much as we can?" If I recover the file the data is still there for all 25,000 rows in both the sheets however the datavalidations i.e. dropdowns are not applied for any of the cells. The recovery log is as follows, while the repair message in the screenshot.
error946360_01.xmlErrors were detected in file 'D:\file.xlsx'Removed Feature: Data validation from /xl/worksheets/sheet.xml partRepaired Records: Cell information from /xl/worksheets/sheet.xml partRepaired Records: Cell information from /xl/worksheets/sheet2.xml part

For me, checking if a row is already existing before adding it did the trick.
Somehow, in the xml schema of the xlsx file (for me it was the sheet1.xml), rows were already existing. After running my code, I added a row with an index, which was already existing.
So try to open your excel with winrar, find sheet1.xml (and sheet2.xml in your case) and see if you have duplicated index for rows.
Generate the excel file with your code and don't open it with excel, otherwise excel will remove the duplicates and you won't see the problem.
Another option would be to validate your excel file (before opening) with the Open Xml SDK 2.5 Productivity Tool

Related

Using PowerAutomate to add multiple rows in excel file when a file is created in a folder(Sharepoint)

I am trying to add rows into an excel file located on Sharepoint when another Excel file is created using Powerpoint. There are always fixed cells which have to be inserted into fixed cells in the other file.
I have tried to initialize a variable (an array) and selected 'apply to each' but that does not work so far.
I was wondering how Powerautomate can possibly recognize the schema of the file to be uploaded (with a variable amount of rows) and thus insert the correct these values into the proper columns?
Does anybody have a suggestion.

Excel Save CSV without blanks

I have an Excel spreadsheet that generates CSV scripts used in an application. The scripts must be in a very specific format, and I save a master in XLSX format with protected sheets and data validation to save the CSVs from rather than directly edit the CSVs, as directly editing the CSVs can lead to mistakes.
The issue is that the scripts can be of nearly any length. The left column of each line can only be one of a certain set of values, and the last line has to say "END". The only way I can do this without VBA is the following formula in the A column, from row 7 (the first 6 are header information) to row 1048576 (last Excel row) and protect the sheet with column A locked:
=IF(AND(ISBLANK(B368),NOT(ISBLANK(B367))),"END",IF(ISBLANK(B368),"",A367))
This makes the last row say "END" in column A, and all rows after blank, which is what is desired. The problem is that now when the CSV file is saved, it will always have 1048576 rows, with all the bottom rows containing the delimiters ",,,," . This won't work, the CSV file needs to stop after the "END" row. Is there a way to write the formula that will cause Excel to ignore the cells which evaluate to blank when saving to CSV or an alternate way to save to CSV in Excel that will ignore all the rows that evaluate to blank?
Note: I have a solution in VBA already that I can use on my own machine (it copies the data up to "END", pastes in a new sheet in text only format, then saves as CSV with the name of the original worksheet). I want to share this sheet, however, and getting around the security constraints to share macros at my company is a pain. So I'm looking for a way this might be done without Macros, if it's possible at all.
In looking for an answer I found this link, which is similar, but not the same:
Saving Excel data as csv with VBA - removing blank rows at end of file to save
As the "blanks" I have are active rows because they contain formulas, this method will not work.
Manually deleting the rows / columns will work to reset the size, as GSerg noted in the other question. Alternatively, also as suggested by GSserg, you can copy the data to a new sheet before saving.
Otherwise, an easy fix might be to create a small post-excel / pre-processing script - perhaps using a batch file - Batch / Find And Edit Lines in TXT file - or a similar solution in any small scripting language to remove the extra rows.

Not able to convert Excel file to CSV

I have an Excel file with 2 sheets. One with my data with headers and the other is for references. It's basically a template where I am using Sheet 2 for reference values. When I save the file to CSV, it saves all garbage data which I think are due to 2 work sheets and the references between them.
Please find the attached excel sheet and let me know how I can do a proper conversion?
Notes:
I am using Office 2010 Standard
I have tried copying and pasting with "Values" option.
I have tried copying and pasting with "Merge Destination Formatting"
Nothing worked.
I was able to find the solution.
When you copy the selected range of records and paste them to New excel file, just drag the cursor some columns ahead. Remove the newly added columns (Not sure from where they come). Now do a Save As CSV. Thats it.

XSSF saving workbook

I am using XSSF to create a workbook and continually getting this error:
Excel found unreadable content in 'thefile'.xlsx. Do you want to recover the contents of this workbook? If you trust the source of the workbook click Yes.
Excel then obligingly recovers it by removing all of the data and gives the detail error report:
Removed Records: Cell information from /xl/worksheets/sheet1.xml part
I am following these principles:
Ensure the row is created and not null.
Ensure the cell is created and not null.
Ensure the cell is the correct type.
Write to cell.
Is there something I am missing, eg is it permissable to have only certain cells written to in a row eg:
|null|null|write something here|null|null|
and the same with rows:
row with content
null
row with content
or do I need to ensure the all rows and columns are filled blank through the ranges used.
This is a complete mystery.

Make excel worksheet mirror worksheet in external file

How can I make a worksheet in my excel file mirror exactly the sheet of a different (closed) worksheet.
Basically, I have around 5 files with a lot of data the gets consolidated into a single dashboard with the important information. I then want to create a file (lets call it report) that has the 'main' sheet from each of these different files.
Ideally, the report file will not have to be altered, and when it is opened it will already have all the data needed.
Note: there are merged cells in the documents that are in variable positions.
response to comment #1:
By be there already, for example you can do a vlookup referencing other workbooks.. and the values of those vlookups will be correct when you open the file. First I thought I could just say cell A1 is file 1 = cell A1 in file 2, but the merged cells throw that off because it will not create merged cells to match
I found the following and it can be done in Excel VBA.
1) open consolidated workbook
2) Assuming that all the files you need to consolidate are in a given directory, you can obtain the list of all these files.
2.1) Traverse the list of files and open them one after the other
2.2) When a file is open, you might want to change the name of the sheet before moving it to the "report" file.
2.3) Close each file without saving them.

Resources