W

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

· 16년 전 · 5885

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

 

우선 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년 전 조회 2,385
15년 전 조회 1,192
15년 전 조회 1,668
15년 전 조회 1,640
15년 전 조회 3,440
15년 전 조회 3,775
15년 전 조회 2,469
15년 전 조회 1,913
15년 전 조회 2,554
15년 전 조회 2,029
15년 전 조회 1,654
15년 전 조회 4,343
15년 전 조회 1,995
15년 전 조회 2,085
15년 전 조회 3,341
15년 전 조회 2,044
15년 전 조회 4,738
15년 전 조회 2,927
15년 전 조회 3,732
15년 전 조회 2,341
15년 전 조회 2,580
15년 전 조회 1,873
16년 전 조회 4,928
16년 전 조회 4,551
16년 전 조회 4,342
16년 전 조회 5,763
16년 전 조회 3,986
16년 전 조회 2,340
16년 전 조회 2,325
16년 전 조회 2,460
16년 전 조회 2,148
16년 전 조회 4,590
16년 전 조회 3,494
16년 전 조회 2,652
16년 전 조회 2,250
16년 전 조회 2,438
16년 전 조회 2,948
16년 전 조회 2,040
16년 전 조회 2,961
16년 전 조회 2,284
16년 전 조회 2,412
16년 전 조회 2,032
16년 전 조회 2,744
16년 전 조회 2,069
16년 전 조회 2,491
16년 전 조회 2,670
16년 전 조회 1,742
16년 전 조회 1,803
16년 전 조회 2,468
16년 전 조회 5,886
16년 전 조회 2,203
16년 전 조회 2,729
16년 전 조회 2,911
16년 전 조회 2,062
16년 전 조회 1,846
16년 전 조회 2,775
16년 전 조회 5,486
16년 전 조회 2,763
16년 전 조회 3,421
16년 전 조회 2,274
16년 전 조회 4,180
16년 전 조회 4,969
16년 전 조회 3,613
16년 전 조회 2,867
16년 전 조회 2,987
16년 전 조회 3,195
16년 전 조회 2,715
16년 전 조회 6,073
16년 전 조회 3,895
16년 전 조회 1,881
16년 전 조회 2,218
16년 전 조회 5,578
16년 전 조회 2,825
16년 전 조회 3,908
16년 전 조회 3,185
16년 전 조회 2,079
16년 전 조회 5,903
16년 전 조회 3,015
16년 전 조회 6,496
16년 전 조회 2,483
16년 전 조회 4,515
16년 전 조회 3,530
16년 전 조회 2,713
16년 전 조회 2,743
16년 전 조회 4,868
16년 전 조회 3,806
16년 전 조회 3,326
16년 전 조회 3,479
16년 전 조회 2,601
16년 전 조회 2,272
16년 전 조회 2,191
16년 전 조회 1,908
16년 전 조회 2,189
16년 전 조회 2,393
16년 전 조회 2,100
16년 전 조회 5,348
16년 전 조회 4,343
16년 전 조회 2,287
16년 전 조회 2,032
16년 전 조회 2,799