Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:41:02+00:00 2026-05-20T10:41:02+00:00

I am using OpenOffice uno api to iterate through all text in writer document.

  • 0

I am using OpenOffice uno api to iterate through all text in writer document. To iterate over text tables currently I am using XTextTable interface getCellNames() method. How I could detect merged and split cells. I want to export table to html, so I should calculate colspan and rowspan.

I would appreciate any suggestions… I am out of ideas 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:41:03+00:00Added an answer on May 20, 2026 at 10:41 am

    Finally I have the answer (actually colspan part of it). This code is ugly I know, but one day I’ll refactor it 😉

    public class Cell
    {
        private List<string> _text = new List<string>();
        public List<string> Text 
        { 
            get { return _text; }
            set { _text = value; }
        }
        public int ColSpan { get; set; }
        public int RowSpan { get; set; }
    
        public Cell(int colSpan, int rowSpan, List<string> text)
        {
            ColSpan = colSpan;
            RowSpan = rowSpan;
            _text = text;
        }
    
        public Cell(int colSpan, int rowSpan)
        {
            ColSpan = colSpan;
            RowSpan = rowSpan;
        }
    }
    

    and here it is table parse method

        public static List<List<Cell>> ParseTable(XTextTable table)
        {
            XTableRows rows = table.getRows() as XTableRows;
            int rowCount = rows.getCount();
            int sum = GetTableColumnRelativeSum(table);
    
            // Temprorary store for column count of each row
            int[] colCounts = new int[rowCount];
    
            List<List<int>> matrix = new List<List<int>>(rowCount);
            for (int i = 0; i < rowCount; i++)
                matrix.Add(new List<int>());
    
            // Get column count for each row
            int maxColCount = 0;
            for (int rowNo = 0; rowNo < rowCount; rowNo++)
            {
                TableColumnSeparator[] sep = GetTableRowSeperators(rows, rowNo);
                colCounts[rowNo] = sep.Length + 1;
    
                if (maxColCount < colCounts[rowNo])
                    maxColCount = colCounts[rowNo];
    
                for (int j = 0; j < sep.Length; j++)
                    matrix[rowNo].Add(sep[j].Position);
    
                matrix[rowNo].Add(sum);
            }
    
            int[] curIndex = new int[rowCount];
            List<List<Cell>> results = new List<List<Cell>>(rowCount);
            for (int i = 0; i < rowCount; i++)
                results.Add(new List<Cell>());
    
            int curMinSep = matrix[0][0];
            do
            {
                curMinSep = matrix[0][curIndex[0]];
                for (int i = 0; i < rowCount; i++)
                    if (curMinSep > matrix[i][curIndex[i]]) curMinSep = matrix[i][curIndex[i]];
    
                for (int rowNo = 0; rowNo < rowCount; rowNo++)
                {
                    int col = curIndex[rowNo];
                    int lastIdx = results[rowNo].Count - 1;
    
                    if (curMinSep == matrix[rowNo][col])
                    {
                        if (colCounts[rowNo] > col + 1) curIndex[rowNo] = col + 1;
    
                        if (results[rowNo].Count > 0 &&
                            results[rowNo][lastIdx].Text.Count < 1 &&
                            results[rowNo][lastIdx].ColSpan > 0)
                        {
                            results[rowNo][lastIdx].ColSpan++;
                            results[rowNo][lastIdx].Text = GetCellText(table, rowNo, col);
                        }
                        else
                        {
                            results[rowNo].Add(new Cell(0, 0, GetCellText(table, rowNo, col)));
                        }
                    }
                    else
                    {
                        if (results[rowNo].Count > 0 &&
                            results[rowNo][lastIdx].Text.Count < 1)
                        {
                            results[rowNo][lastIdx].ColSpan++;
                        }
                        else
                        {
                            results[rowNo].Add(new Cell(1, 0));
                        }
                    }
                }
            } while (curMinSep < sum);
    
            return results;
        }
    
        public static short GetTableColumnRelativeSum(XTextTable rows)
        {
            XPropertySet xPropertySet = rows as XPropertySet;
            short sum = (short)xPropertySet.getPropertyValue("TableColumnRelativeSum").Value;
            return sum;
        }
    
        public static TableColumnSeparator[] GetTableRowSeperators(XTableRows rows, int rowNo)
        {
            XPropertySet rowProperties = rows.getByIndex(rowNo).Value as XPropertySet;
            TableColumnSeparator[] sep = null;
            sep = rowProperties.getPropertyValue("TableColumnSeparators").Value as TableColumnSeparator[];
            return sep;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to save a TextDocument created through OpenOffice.org UNO to a file on
I'm currently trying to do a mailmerge, using C# and OpenOffice. I have a
I am trying to create an OpenOffice Calc chart using the OOoTools.pas interface. The
Background OpenOffice Writer lacks the ability to link to an ASCII text source file,
I am using openoffice sdk to get all info from doc file, what I
I am using OpenOffice.org for most of my not so very frequent Office Suite
How do I import a CSV file using OpenOffice.org APIs? I want to do
I need to do a simple mail merge in OpenOffice using C++, VBScript, VB.Net
I am using OpenOffice in my system and already I tried about it, also
I am using OpenOffice SDK to open and parse ppt and pptx files; now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.