我希望阅读一个Excel文件并跳过空行。我的代码跳过空单元格,但它也会跳过空列。如何跳过空行但保留空列?我正在使用JXL Java。
page = get(<url goes here>)
page.json()
...
答案 0 :(得分:1)
试试这个:
for (int i = 0; i < sheet.getRows(); i++) {
boolean rowEmpty = true;
String currentRow = "";
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i);
String con=cell.getContents();
if(con !=null && con.length()!=0){
rowEmpty = false;
}
currentRow += con + "|";
}
if(!rowEmpty) {
System.out.println(currentRow);
}
}
你在做的是:
这是做什么的:
答案 1 :(得分:0)
在 C# 的情况下,这对我有用
public class TestMap extends ApplicationAdapter implements InputProcessor{
TiledMap tiledMap;
OrthographicCamera camera;
TiledMapRenderer tiledMapRenderer;
SpriteBatch sb;
Texture texture;
Sprite sprite;
@Override
public void create () {
camera = new OrthographicCamera();
camera.setToOrtho(false,320,320);
camera.update();
tiledMap = new TmxMapLoader().load("testmap.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
Gdx.input.setInputProcessor(this);
sb = new SpriteBatch();
texture = new Texture(Gdx.files.internal("pikachu.png"));
sprite = new Sprite(texture);
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
tiledMapRenderer.setView(camera);
tiledMapRenderer.render();
sb.begin();
sprite.draw(sb);
sb.end();
}
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
if(keycode == Input.Keys.LEFT)
camera.translate(0,32);
if(keycode == Input.Keys.RIGHT)
camera.translate(0,-32);
if(keycode == Input.Keys.UP)
camera.translate(32,0);
if(keycode == Input.Keys.DOWN)
camera.translate(-32,0);
if(keycode == Input.Keys.NUM_1)
tiledMap.getLayers().get(0).setVisible(!tiledMap.getLayers().get(0).isVisible());
if(keycode == Input.Keys.NUM_2)
tiledMap.getLayers().get(1).setVisible(!tiledMap.getLayers().get(1).isVisible());
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
}