DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • Get Ready for Android 15: Must-Have Testing Strategies for Effective Updates
  • How To Create a Homescreen Widget in Android
  • How Does WebView Actually Work on Android?
  • How To Integrate Chatbot With an Android App

Trending

  • 4 Essential Strategies for Enhancing Your Application Security Posture
  • Wow, pnpm, You’re Really Fast
  • Data Governance Essentials: Glossaries, Catalogs, and Lineage (Part 5)
  • Accelerating Connection Handshakes in Trusted Network Environments
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Read Worksheet Cells Values in Multiple Threads in Android Apps

How to Read Worksheet Cells Values in Multiple Threads in Android Apps

By 
David Zondray user avatar
David Zondray
·
Oct. 29, 14 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
2.2K Views

Join the DZone community and get the full member experience.

Join For Free

This technical tip shows how to read Excel worksheet cells values in multiple threads simultaneously inside android applications.  Often you need to read worksheet cells values in multiple threads simultaneously. To do so, set Worksheet.getCells().setMultiThreadReading() to true. If you do not set this property you might get the wrong cell values. Setting it to true, you always get the correct values. To achieve this task first create a workbook and adds a worksheet. Populates the worksheet with some string values then create two threads that simultaneously read values from random cells. If the values read are correct, then nothing happens. But if the values read are incorrect, then a message box shows up in the LogCat window. If you comment this line:
testWorkbook.getWorksheets().get(0).getCells().setMultiThreadReading(true);
the following message will show up in LogCat window:
if (s.equals("R" + row + "C" + col)!=true)
{
    System.out.println("This message box will show up when cells read values are incorrect.");
}
Otherwise, the program run without showing any message which means all values read from cells are correct.

public class ThreadProc implements Runnable {

	boolean isRunning = true;
	Workbook testWorkbook;
	Random r = new Random();

	public ThreadProc(Workbook workbook)
	{
		this.testWorkbook = workbook;
	}

	public int randomNext(int Low, int High)
	{
		int R = r.nextInt(High-Low) + Low;
		return R;
	}

	public void kill()
	{
		this.isRunning = false;
	}

    public void run(){

    	while(this.isRunning)
    	{
            int row = randomNext(0, 100);
            int col = randomNext(0, 10);

            String s = testWorkbook.getWorksheets().get(0).getCells().get(row, col).getStringValue();

            if (s.equals("R" + row + "C" + col)!=true)
            {
                System.out.println("This message box will show up when cells read values are incorrect.");
            }
    	}
    }
  }


//........MainActivity.java........
//.................................
import java.io.File;
import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;

import com.aspose.cells.CellsHelper;
import com.aspose.cells.IWarningCallback;
import com.aspose.cells.WarningInfo;
import com.aspose.cells.WarningType;
import com.aspose.cells.Workbook;

public class MainActivity extends Activity {

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
try{
    Workbook testWorkbook = new Workbook();
    testWorkbook.getWorksheets().clear();
    testWorkbook.getWorksheets().add("Sheet1");

    for (int row = 0; row < 100; row++)
        for (int col = 0; col < 10; col++)
            testWorkbook.getWorksheets().get(0).getCells().get(row, col).setValue("R" + row + "C" + col);

    //Commenting this line will show a pop-up message
    testWorkbook.getWorksheets().get(0).getCells().setMultiThreadReading(true);

    ThreadProc tp = new ThreadProc(testWorkbook);

    Thread myThread1 = new Thread(tp);
    myThread1.start();

    Thread myThread2 = new Thread(tp);
    myThread2.start();

    Thread.currentThread().sleep(5*1000);
    tp.kill();
}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

.........

}

Android (robot)

Opinions expressed by DZone contributors are their own.

Related

  • Get Ready for Android 15: Must-Have Testing Strategies for Effective Updates
  • How To Create a Homescreen Widget in Android
  • How Does WebView Actually Work on Android?
  • How To Integrate Chatbot With an Android App

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: