W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5399

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,858
15년 전 조회 673
15년 전 조회 1,155
15년 전 조회 1,125
15년 전 조회 2,913
15년 전 조회 3,232
15년 전 조회 1,902
15년 전 조회 1,414
15년 전 조회 2,028
15년 전 조회 1,540
15년 전 조회 1,140
15년 전 조회 3,826
15년 전 조회 1,476
15년 전 조회 1,574
15년 전 조회 2,797
15년 전 조회 1,496
15년 전 조회 4,224
15년 전 조회 2,436
15년 전 조회 3,218
15년 전 조회 1,826
15년 전 조회 2,057
15년 전 조회 1,363
15년 전 조회 4,435
15년 전 조회 4,018
15년 전 조회 3,840
15년 전 조회 5,259
15년 전 조회 3,488
15년 전 조회 1,868
15년 전 조회 1,810
15년 전 조회 1,955
15년 전 조회 1,656
15년 전 조회 4,055
15년 전 조회 2,982
15년 전 조회 2,147
16년 전 조회 1,736
16년 전 조회 1,965
16년 전 조회 2,456
16년 전 조회 1,526
16년 전 조회 2,460
16년 전 조회 1,793
16년 전 조회 1,898
16년 전 조회 1,541
16년 전 조회 2,244
16년 전 조회 1,570
16년 전 조회 1,985
16년 전 조회 2,170
16년 전 조회 1,241
16년 전 조회 1,314
16년 전 조회 1,956
16년 전 조회 5,400
16년 전 조회 1,703
16년 전 조회 2,224
16년 전 조회 2,414
16년 전 조회 1,561
16년 전 조회 1,365
16년 전 조회 2,287
16년 전 조회 5,001
16년 전 조회 2,273
16년 전 조회 2,927
16년 전 조회 1,809
16년 전 조회 3,655
16년 전 조회 4,499
16년 전 조회 3,154
16년 전 조회 2,413
16년 전 조회 2,500
16년 전 조회 2,740
16년 전 조회 2,232
16년 전 조회 5,573
16년 전 조회 3,423
16년 전 조회 1,420
16년 전 조회 1,760
16년 전 조회 5,132
16년 전 조회 2,376
16년 전 조회 3,469
16년 전 조회 2,709
16년 전 조회 1,617
16년 전 조회 5,423
16년 전 조회 2,533
16년 전 조회 6,032
16년 전 조회 2,004
16년 전 조회 4,080
16년 전 조회 3,090
16년 전 조회 2,283
16년 전 조회 2,290
16년 전 조회 4,443
16년 전 조회 3,362
16년 전 조회 2,885
16년 전 조회 3,031
16년 전 조회 2,152
16년 전 조회 1,834
16년 전 조회 1,747
16년 전 조회 1,465
16년 전 조회 1,731
16년 전 조회 1,969
16년 전 조회 1,660
16년 전 조회 4,905
16년 전 조회 3,885
16년 전 조회 1,857
16년 전 조회 1,599
16년 전 조회 2,342