想要在Java中的Excel中打印特定单元格的所有行值

时间:2019-07-31 10:22:32

标签: java selenium

获得特定项目的名称和价格后,我将其存储在excel表中。现在,我比较它们的价格并获得最低价格,但是如何打印最低价格的所有细节

我的代码是

using System;
using System.IO;

namespace OggVorbisEncoder.Example
{
    public class Encoder
    {
        private const int SampleSize = 1024;

        [STAThread]
        private static void Main()
        {
            var stdin = new FileStream(@"unencoded.raw", FileMode.Open, FileAccess.Read);
            var stdout = new FileStream(@"encoded.ogg", FileMode.Create, FileAccess.Write);

            // StripWavHeader(stdin);

            // Stores all the static vorbis bitstream settings
            var info = VorbisInfo.InitVariableBitRate(2, 44100, 0.1f);

            // set up our packet->stream encoder
            var serial = new Random().Next();
            var oggStream = new OggStream(serial);

            // =========================================================
            // HEADER
            // =========================================================
            // Vorbis streams begin with three headers; the initial header (with
            // most of the codec setup parameters) which is mandated by the Ogg
            // bitstream spec.  The second header holds any comment fields.  The
            // third header holds the bitstream codebook.
            var headerBuilder = new HeaderPacketBuilder();

            var comments = new Comments();
            comments.AddTag("ARTIST", "TEST");

            var infoPacket = headerBuilder.BuildInfoPacket(info);
            var commentsPacket = headerBuilder.BuildCommentsPacket(comments);
            var booksPacket = headerBuilder.BuildBooksPacket(info);

            oggStream.PacketIn(infoPacket);
            oggStream.PacketIn(commentsPacket);
            oggStream.PacketIn(booksPacket);

            // Flush to force audio data onto its own page per the spec
            OggPage page;
            while (oggStream.PageOut(out page, true))
            {
                stdout.Write(page.Header, 0, page.Header.Length);
                stdout.Write(page.Body, 0, page.Body.Length);
            }

            // =========================================================
            // BODY (Audio Data)
            // =========================================================
            var processingState = ProcessingState.Create(info);

            var buffer = new float[info.Channels][];
            buffer[0] = new float[SampleSize];
            buffer[1] = new float[SampleSize];

            var readbuffer = new byte[SampleSize*4];
            while (!oggStream.Finished)
            {
                var bytes = stdin.Read(readbuffer, 0, readbuffer.Length);

                if (bytes == 0)
                {
                    processingState.WriteEndOfStream();
                }
                else
                {
                    var samples = bytes/4;

                    for (var i = 0; i < samples; i++)
                    {
                        // uninterleave samples
                        buffer[0][i] = (short) ((readbuffer[i*4 + 1] << 8) | (0x00ff & readbuffer[i*4]))/32768f;
                        buffer[1][i] = (short) ((readbuffer[i*4 + 3] << 8) | (0x00ff & readbuffer[i*4 + 2]))/32768f;
                    }

                    processingState.WriteData(buffer, samples);
                }

                OggPacket packet;
                while (!oggStream.Finished
                       && processingState.PacketOut(out packet))
                {
                    oggStream.PacketIn(packet);

                    while (!oggStream.Finished
                           && oggStream.PageOut(out page, false))
                    {
                        stdout.Write(page.Header, 0, page.Header.Length);
                        stdout.Write(page.Body, 0, page.Body.Length);
                    }
                }
            }

            stdin.Close();
            stdout.Close();
        }

        /// <summary>
        ///     We cheat on the WAV header; we just bypass the header and never
        ///     verify that it matches 16bit/stereo/44.1kHz.This is just an
        ///     example, after all.
        /// </summary>
        private static void StripWavHeader(BinaryReader stdin)
        {
            var tempBuffer = new byte[6];
            for (var i = 0; (i < 30) && (stdin.Read(tempBuffer, 0, 2) > 0); i++)
                if ((tempBuffer[0] == 'd') && (tempBuffer[1] == 'a'))
                {
                    stdin.Read(tempBuffer, 0, 6);
                    break;
                }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

似乎不需要嵌套循环,并且需要将其他单元格存储到字符串变量中。请尝试以下代码。

    File file = new File("phone_compare.xlsx");
    FileInputStream fs = new FileInputStream(file);

    XSSFWorkbook wb=new XSSFWorkbook(fs);
    String min = wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue();
    int value_min = Integer.parseInt(min.substring(1).replace(",", ""));

    String getText = null;

    String str1 =  wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue();
    String str2 =  wb.getSheetAt(0).getRow(0).getCell(2).getStringCellValue();
    getText = str1 +" " +value_min +" " +str2;
    XSSFSheet sh1= wb.getSheetAt(0);


    for (int i = 0; i <=sh1.getLastRowNum(); i++) {

        String c =  wb.getSheetAt(0).getRow(i).getCell(1).getStringCellValue();

        int value = Integer.parseInt(c.substring(1).replace(",", ""));

        if(value < value_min) {
            value_min=value;
            str1 =  wb.getSheetAt(0).getRow(i).getCell(0).getStringCellValue();
            str2 =  wb.getSheetAt(0).getRow(i).getCell(2).getStringCellValue();
            getText = str1 +" " +value_min +" " +str2;



    }

}    
System.out.println(getText);
}