ReoGrid icon indicating copy to clipboard operation
ReoGrid copied to clipboard

Grid Excel Custom Export function

Open ByungchunBang opened this issue 4 years ago • 6 comments

Describe the feature

I need custom excel export function. condition

  • display grid's layout have to not changed.
  • only export excel file's 3rd row need to deleted.

so , i made code as below.

        var grid_memory =  unvell.ReoGrid.ReoGridControl.CreateMemoryWorkbook();
        grid_memory.AddWorksheet(grid_test.CurrentWorksheet); // grid_test is UI grid.
        grid_memory.Worksheets[0].DeleteRows(3, 1);
        grid_memory.Save("test.xls");          

but i got error message. unvell.ReoGrid.WorkbookException: 'Specified worksheet belongs to another workbook, remove from another workbook firstly.'

could you advise ?

Which edition of ReoGrid is targeted

  • WPF

ByungchunBang avatar Jul 19 '21 08:07 ByungchunBang

Maybe you have to clone the worksheet?

grid_memory.AddWorksheet(grid_test.CurrentWorksheet.Clone());

jingwood avatar Jul 27 '21 13:07 jingwood

Hi Jingwood, Thanks for your reply. I applied that code but i got same error. image

ByungchunBang avatar Jul 28 '21 00:07 ByungchunBang

OK, I will check this and reply you if there is a solution.

jingwood avatar Jul 28 '21 00:07 jingwood

Hello, @jingwood As to my check with function public Clone(string newName = null) ( line 36 file Reogrid\ReoGrid\Core\Worksheet\Utility.cs ) It always checks workbook not null, then after clone, it's always stick to existing workbook. ( line 38 ) My proposals: 1- Add new function SwitchWorkbook( IWorkbook wb )

  • this declare new Worksheet, add to wb
  • remove current worksheet

2- Change line 36 to public Worksheet Clone(string newName = null, IWorkbook? wb = null)

  • if wb not null, do not thought Exception
  • line 48 change this.workbook to wb if wb not null

Let me know what do you think. PS: great work with Reogrid. Thanks for a nice product. Regards, Minh

smpleader avatar Apr 11 '23 09:04 smpleader

@smpleader Thank you for your suggestion.

Moving a worksheet from one workbook to another can be a complex process, as named ranges and formulas may still contain references to other worksheets inside the original workbook. I'm considering the following workflow:

  1. Clone the worksheet and remove all references.
  2. Insert the cloned worksheet into the new workbook.
  3. Delete the original worksheet from the old workbook.

The cloning operation is crucial for addressing issues related to references. I recall that the problem lies in the fact that cloning doesn't remove the reference to the old workbook. Perhaps the solution for this issue is to ensure that the cloning process removes the reference from the old workbook. What do you think about this approach?

jingwood avatar Apr 12 '23 06:04 jingwood

Hello @jingwood I agree with your approach. In any case, the developer should be aware of referenced cells, at his side. We can consider the extra: 1- Clone a workbook 2- Safe clone: check if any reference of sheet before the clone to new workbook More about scenario: I would like to use Memory workbook as a storage, and show a certain sheet in a different form. Looking forward to hear more from you. Thank you.

smpleader avatar Apr 12 '23 07:04 smpleader