Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Apr 19, 2023 3:01 am

I extract a table to excel as:

Code: Select all
string str= @"D:\t2.pdf";           
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
             doc.LoadFromFile(str);
            PdfTableExtractor extractor = new PdfTableExtractor(doc);           
            PdfTable[] tableLists = extractor.ExtractTable(0);         
            if (tableLists != null && tableLists.Length > 0)
            {
                //Loop through the table in the list
                foreach (PdfTable table in tableLists)
                {
                    //Get row number and column number of a certain table
                    int iTotalRow = table.GetRowCount();
                    int iTotalCol = table.GetColumnCount();
                    //OutputExcel
                     //Loop though the row and colunm
                        for (int iRow = 0; iRow < iTotalRow; iRow++)
                        {
                            for (int iCol = 0; iCol < iTotalCol; iCol++)
                            {
                                //Get text from the specific cell
                                string text = table.GetText(iRow, iCol);                           
                                worksheet.Cells[iRow + 1, iCol + 1].Value = text;                             
                            }
                           
                        }                     
                 
                }
            }


Table:

t21.JPG


Result:
t22.JPG


Can merge cells at Column A the same PDF Table? (Which blank cells are part of Merged Cell?)

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Wed Apr 19, 2023 9:32 am

Hi,

Thank you for your inquiry. Currently, there is no direct way to achieve this conversion. However, there are some indirect methods that can be used to accomplish this task.

One approach is to first convert the PDF file to a Word document, then locate the table and obtain its merge properties. Next, the data can be written into an Excel worksheet, and the appropriate cells can be merged based on the obtained merge information.

Please note that this method may be hard to achieve, as you need to consider many situations. If you need assistance with this process, please let us know and we will do our best to provide guidance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Apr 19, 2023 9:55 am

I think your Lib can detect Cell Merged.
Can you provide this feature?
Ex:
If Cell is a Part of Merge [table.GetText(iRow, iCol); ] return value = [null]
If Cell is Blank return value = empty.

Or
You can provide the get ID function of the Cell that is getting the text with border . I can merge cells with the same ID together.

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Thu Apr 20, 2023 3:23 am

Hi,

Thank you for your inquiry about our PDF product's ability to detect merged tables. Our product does not have the concept of individual cells or tables, it identifies tables based on the intersection of horizontal and vertical lines. Therefore, the product relies on these lines to extract tables.
I am sorry that our Spire.PDF is currently unable to meet your needs. Please let us know if you have any further questions or concerns.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Apr 20, 2023 3:34 am

[it identifies tables based on the intersection of horizontal and vertical lines.]
=>Yes, Each Rectangle has an ID, and Cells can be merged if they have the same ID.

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Thu Apr 20, 2023 8:47 am

Hi,

Thanks for your inquiry.
We regret to inform you that PDF cells do not have IDs as they are generated based on horizontal and vertical lines. Regarding the so-called "merged" cells, they are actually a single entity and are not formed by combining multiple smaller cells like what can be done in Excel.

If you have any questions regarding our product, please do not hesitate to contact us. We are always here to help.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Apr 21, 2023 2:19 am

We regret to inform you that PDF cells do not have IDs as they are generated based on horizontal and vertical lines.

=>Not the ID of the PDF, but the ID you define when you get text by border
Ex:
table2id.png



So the cells in column 1 will have the same ID

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Fri Apr 21, 2023 6:25 am

Hi,

Our product judges whether it is a cell or not based on whether the lines intersect. For example, in the following screenshots, the E cell does not intersect with any lines, so it is considered as a standalone cell. The green line is a subjective thought, and it does not exist in our product.
test.png
test3.png

Therefore, we cannot determine whether a cell is merged or not with certainty. Hope that you can understand.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Apr 24, 2023 4:34 am

Yes, So You can define a ID of Cell E, Ex ID of Cell E="3"
[table.GetText(0, 2); ] return value = [E]
[table.GetText(1, 2); ] return value = [empty]

And Can you return a ID of Cell(0,2) and Cell (1,2)?
Ex:
table.GetID(0, 2) return ID="3" and table.GetID(1, 2) return ID="3"

daitranthanhhoa
 
Posts: 51
Joined: Mon Sep 19, 2016 3:04 am

Mon Apr 24, 2023 8:03 am

Hi,

Thanks for your reply.
Our PDF cells do not have IDs, I am afraid that your requirement will not be satisfied, apologize for any inconvenience this may have caused. Thanks for your understanding.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF